Question

I asked this yesterday, but I don't think I was clear...

I'm using a WordPress theme that has a simple PHP contact form that allows users to email each other. However, when one user sends an email to another, it's showing my WordPress admin email as who it's from and not the email address the user inputs in the email field when they fill out the form. (The form just consists of "Your Email" and "Your Message")

Here is a pic of the code:

screenshot http://urbansheet.com/imgs/contact-sample.jpg

  • The GREEN area references the user's address who is receiving the email.

  • The RED area references the title of the post the user is emailing about and shows up as the email Subject.

  • The PURPLE area obviously references "Your Message".

  • The ORANGE area displays in the body of the email and ".$email" does put the senders email address there.

But, like I said, I need emails to be "from" the sender's email address, not from my WordPress admin email. It serves no purpose if the receiver clicks Reply in their email account, they'll just be replying to my Admin address and not to the sender.

The way it is now, in order for the receiver to reply, they have to copy and paste the senders email out of the body of the email into a new email. Hardly convenient.

Was it helpful?

Solution

If you set the message as from the sender's email, you are more likely to be trapped in spam filters (since the sender's server doesn't actually originate the message... yours does).

Rather, set a Reply-To: header with the sender's email. Without seeing what you're doing in send_email() function, it's hard to know how you'd implement that. With PHP's mail(), it's easy.

<?php
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: sender@example2.com';

mail( 'recipient@example2.com', 'subject', 'message', $headers);

Just include the Reply-To: header along with the "sender's" email address when you invoke send_email().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top