0

I'm using a theme that has a built in contact form, which has some options (like where the form is sent) set through the OptionTree plugin.

What's happening is, the email gets sent, but the reply-to is a made-up server address at the webhost, rather than what the visitor's self-stated email is. This is really weird.

When I look at the code, it all seems sound:

//If there is no error, send the email
if(!isset($hasError)) {
    $emailTo = get_option_tree( 'contact_page_email' );  /*Put your own email address here*/ 
    $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
    $headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

    mail($emailTo, $subject, $body, $headers);
    $emailSent = true;
}

It looks like the code is supposed to set reply-to to be the person's stated email address. But our mail server, for some reason, wants to set the reply for all form responses to a server-generated address. The reply-to address ends up being [email protected].

Does anyone have any ideas why this might be happening? The code looks sound to me -- I just can't figure out why when we receive mail from the server from the contact form, it appears to come from an address that isn't the client's email.

Thanks!

Rob

4
  • 2
    Always use wp_mail(), not mail().
    – fuxia
    Jan 12, 2013 at 7:48
  • 1
    If you echo/var_dump the $headers what do you get? I Jan 12, 2013 at 12:14
  • Hey all, thanks for responding. Toscho, I've tried to replace the mail function with wp_mail. Even if it's the right thing to do, it doesn't seem to have any effect on the apparent sender. Here's my new code: if(!isset($hasError)) { $message = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments"; $headers = 'From: Wordpress <[email protected]>' . "\r\n"; wp_mail('[email protected]', 'Contact from our website form', $message, $headers, $attachments); $emailSent = true; }
    – Rob Butz
    Jan 13, 2013 at 1:31
  • Mark, I'm not sure where I'd get to see the dump of the $headers. Console? Somewhere else? The form uses an AJAX submission so that you stay on the same page and erases the form as soon as you send.
    – Rob Butz
    Jan 13, 2013 at 1:33

1 Answer 1

1

Try this format: Reply-To: John Doe<[email protected]>.

Ref: http://blackwidows.co.uk/blog/2006/10/02/reply-to-header-can-create-bounces/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.