• How can I change forms to be sent by the email that user entered into Email input field in the form and not by the wodpress?
    I can’t find right $user_email value…I just got it to be send by the loged in user, and that is not what I want.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator bcworkz

    (@bcworkz)

    Use the filter ‘wp_mail_from’ for the address and ‘wp_mail_from_name’ for the “friendly” From: text. This will be applied to all site emails so you will want to remove these filters once the message has been sent.

    To get the values to return in the filters, it depends on what is done to process the form submittal. If your script is processing the form then you get the values from $_POST['field_name'] or $_GET['field_name'] depending on which form method is used. Of course ‘field_name’ will be changed to the actual field name.

    Thread Starter jpacijent

    (@jpacijent)

    I tried that before but i get “unknown sender” in mail

    Moderator bcworkz

    (@bcworkz)

    Some host’s mail servers will not send email unless it’s from a domain registered for their servers. An anti-spam measure. It sounds like this is what’s happening here.

    Thread Starter jpacijent

    (@jpacijent)

    Are you shoure? I tested it with my hardcoded email and it worked.

    Moderator bcworkz

    (@bcworkz)

    Nope, I know nothing, I just make (barely) educated guesses! ??

    Another guess: It could be some other plugin or your theme is doing something with the previously mentioned filters. Try adding your callbacks with a high priority number so your callback has the last word. add_filter('wp_mail_from','my_callback',999)

    If all else fails, deactivate all of your plugins and switch to a twenty* theme. Add your filters in their own custom plugin with only absolutely required supporting code, this will be the only plugin active. The mail should work. Switch back to your theme and test. Re-activate each plugin one at a time, testing after each activation. When the test fails you’ve found the problem code source.

    Thread Starter jpacijent

    (@jpacijent)

    ?? thanks!
    Host claims it’s not on their side, and a 100$ wordpress theme support said: “Unfortunately by default our theme has not such functionality. Only option is to use third party plugins but we don’t guaranty proper work of our themes with 3rd party plugins.”
    ?!?!??!
    oooooooook…..let’s start digging

    Moderator bcworkz

    (@bcworkz)

    Yeah, it’s never the hosts fault ?? In this case I believe them, seeing that your hardcoded test worked. The filter I suggested essentially is the “third party plugin”, even if you placed it in functions.php.

    Something is funky with the filters, either other code is messing with it or there’s a glitch in how you hooked the filter or altered the default data. A couple other things you can dig into besides deactivating things: Check the “unknown sender” bounce for what was in the From: field. If it’s not in the bounce message, it should be in the header somewhere. You could also use the ‘wp_mail’ filter to check what parameters are actually being used to send the mail. How the From: field is “unkonwn” could be an indication of where the problem lies.

    Thread Starter jpacijent

    (@jpacijent)

    these are the filters in functions.php:
    add_filter( ‘wp_mail_from’, ‘custom_wp_mail_from’);
    function custom_wp_mail_from($original_email_address) {
    return $_POST[’email’];
    }

    add_filter( ‘wp_mail_from_name’, ‘custom_wp_mail_from_name’);
    function custom_wp_mail_from_name($original_email_from) {
    return ‘Booking form’;
    }

    this is the input field:
    <input id=”sc_contact_form_email” type=”text” name=”email” placeholder=”E-mail *”>
    ….o I don’t think that its problem with how I put filters.

    And there is no bouncing message….it’s just that From is “<>”….empty..hmm

    Moderator bcworkz

    (@bcworkz)

    It could be that $_POST['email'] is no longer valid by the time the filter fires. One way to check is to insert error_log('Posted email: '.$_POST['email']); in your callback, then check your error log.

    I’m suggesting error_log() because I’m not sure print_r() will work in this context. The other approach is to use the output buffer to capture output, then echo it out when echoing will actually work, like in the footer or something. It depends on what is displayed after the email is sent.

    If $_POST['email'] does turn out to be empty, then you’ll need to store the value when the form is processed for later use in the callback. The easiest way to store values is global variables. Everyone loves to hate globals, but they are convenient. If globals bother you, you can work out an alternative later.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Email sent by the email that user entered into Email input field in the form’ is closed to new replies.