WordPress.org

Support

Support » Plugins and Hacks » Ninja Forms » [Resolved] Use name as 'from' name in email address

[Resolved] Use name as 'from' name in email address

  • Hi,

    In the same way that you can click “Use this as the ‘From’ email address for Administrative recepients of this form? ” on a textbox.

    Is there anyway to change it so it can “Use this as the “From” name for Administrative recepients of this form?”

    So it pulls the email from one textbox and the name from another?

    At the moment the email comes through with the submitted email address fine but the name is WordPress and is slightly annoying and hard to organise my bookings.

    http://wordpress.org/extend/plugins/ninja-forms/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Kevin Stover

    @kstover

    Hey,

    We’re probably going to be adding this in as an option in the near future, but you can follow the tutorial here: http://wpninjas.com/change-the-from-email-address-dynamically-with-ninja-forms/ if you would like to add this before we officially release it. Just make sure that you uncheck the “Use this as the ‘From’ email address” in the field settings.

    Hi,

    Thanks for your reply.

    I can’t get it to work. Here’s what I have done:

    1. Added the folder ‘booking-name’ to the folder ‘wp-content/plugins’ and the file ‘booking-name.php’ within the ‘booking-name’ folder.

    2. Put this into the .php file:

    <?php
    /*
    Plugin Name: My Custom Functions
    */
    add_action( 'ninja_forms_email_admin', 'ninja_forms_change_from_address' );
    function ninja_forms_change_from_address(){
       global $ninja_forms_processing;
       if( 1 == $ninja_forms_processing->get_form_ID( 1 ) ) {
        $user_email = $ninja_forms_processing->get_field_value( 5 );
        $user_name = $ninja_forms_processing->get_field_value( 4 );
        $user_email = $user_name." <".$user_email.">";
        $ninja_forms_processing->update_form_setting( 'email_from', $user_email );
       }
    }

    I put the number 5 in because that’s the field id of the email address and 4 is the field id of the name. Put a 1 in the brackets as that’s my form id.

    3. Saved it all and it doesn’t work. Now nothing comes through to my email. I unchecked the option in the form aswell.

    Plugin Author James Laws

    @jameslaws

    The first problem I see with this is this line…

    if( 1 == $ninja_forms_processing->get_form_ID( 1 ) ) {

    Inside the get_form_ID() function you should be trying to set the form ID. It’s getting the current form’s ID for you. Providing that your form ID is 1 it should look like this…

    if( 1 == $ninja_forms_processing->get_form_ID() ) {

    This checks to see if the current form being processed is in fact ID 1. If not it does nothing, if so it will process the code you have inside the if statement.

    Yeh sorry i forgot to remove that. I put it in there just to try it as it wasn’t working. However the problem was that I hadn’t gone to the plugins and activated it.

    Works perfectly now.

    Thank you!

    Plugin Author James Laws

    @jameslaws

    Awesome, and yes, a crucial step.

    Glad you got it all working.

    I have another form on a different page.

    Do I copy duplicate the code and switch the form id and field id?

    Plugin Author Kevin Stover

    @kstover

    Yes. You would copy it and change the appropriate values.

    I take it not like this as this stops the whole site working:

    <?php
    /*
    Plugin Name: My Custom Functions
    */
    
    add_action( 'ninja_forms_email_admin', 'ninja_forms_change_from_address' );
    function ninja_forms_change_from_address(){
       global $ninja_forms_processing;
       if( 1 == $ninja_forms_processing->get_form_ID( ) ) {
        $user_email = $ninja_forms_processing->get_field_value( 5 );
        $user_name = $ninja_forms_processing->get_field_value( 4 );
        $user_email = $user_name." <".$user_email.">";
        $ninja_forms_processing->update_form_setting( 'email_from', $user_email );
       }
    }
    
    add_action( 'ninja_forms_email_admin', 'ninja_forms_change_from_address' );
    function ninja_forms_change_from_address(){
       global $ninja_forms_processing;
       if( 2 == $ninja_forms_processing->get_form_ID( ) ) {
        $user_email = $ninja_forms_processing->get_field_value( 23 );
        $user_name = $ninja_forms_processing->get_field_value( 26 );
        $user_email = $user_name." <".$user_email.">";
        $ninja_forms_processing->update_form_setting( 'email_from', $user_email );
       }
    }

    Plugin Author Kevin Stover

    @kstover

    You just need to change the name of the function. It has to be unique. Just make sure that you change the name in the second part of the add_action as well.

    Hmm strange, this doesn’t work.
    It still comes through as the standard admin:

    <?php
    /*
    Plugin Name: My Custom Functions
    */
    
    add_action( 'ninja_forms_email_admin', 'ninja_forms_change_from_address' );
    function ninja_forms_change_from_address(){
       global $ninja_forms_processing;
       if( 1 == $ninja_forms_processing->get_form_ID( ) ) {
        $user_email = $ninja_forms_processing->get_field_value( 5 );
        $user_name = $ninja_forms_processing->get_field_value( 4 );
        $user_email = $user_name." <".$user_email.">";
        $ninja_forms_processing->update_form_setting( 'email_from', $user_email );
       }
    }
    
    add_action( 'ninja_forms_name_admin', 'ninja_forms_change_from_name' );
    function ninja_forms_change_from_name(){
       global $ninja_forms_processing;
       if( 2 == $ninja_forms_processing->get_form_ID( ) ) {
        $user_email = $ninja_forms_processing->get_field_value( 25 );
        $user_name = $ninja_forms_processing->get_field_value( 26 );
        $user_email = $user_name." <".$user_email.">";
        $ninja_forms_processing->update_form_setting( 'email_from', $user_email );
       }
    }

    Plugin Author Kevin Stover

    @kstover

    The name change is going to be a feature that we add into the plugin in our weekly update. It’ll be live sometime on Monday. Then you won’t need the code at all. We’ve had several requests for this, so we’re just going to add it into the core of the plugin.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Resolved] Use name as 'from' name in email address’ is closed to new replies.
Skip to toolbar