beaner_06 Posted February 22, 2010 Share Posted February 22, 2010 Hello, I have attached my PHP code. The script works fine and sends the e-mail, but in my Gmail inbox, the e-mail shows it is from 'Nobody' (attached img). Is there a way I can change this? Would I use a $header variable? Thanks in advance. <?php if(isset($_POST['submit'])) { $to = "[email protected]"; $subject = "Contact Form"; $firstname_field = $_POST['first']; $lastname_field = $_POST['last']; $email_field = $_POST['email']; $phone_field = $_POST['phone']; $order_field = $_POST['ordernum']; $topic_field = $_POST['topic']; $comments = $_POST['comments']; $body = " From: $firstname_field $lastname_field\n\n E-Mail: $email_field\n\n Phone #: $phone_field\n\n Order #: $order_field\n\n Topic: $topic_field\n\n Comments: $comments"; header ("Location: http://www.ryanbuening.com/thankyou.html"); mail($to, $subject, $body); } else { echo "Error!"; } ?> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/192989-php-mailer-from-nobody/ Share on other sites More sharing options...
mapleleaf Posted February 22, 2010 Share Posted February 22, 2010 <?php $to = '[email protected]'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> from http://php.net/manual/en/function.mail.php which is a really good resource Link to comment https://forums.phpfreaks.com/topic/192989-php-mailer-from-nobody/#findComment-1016357 Share on other sites More sharing options...
beaner_06 Posted February 22, 2010 Author Share Posted February 22, 2010 Awesome. Thanks, that worked. I tried including the e-mail variable (shown below) to the 'Reply-To:' field so that when I hit reply it would reply to the person who filled out the contact form. This did not work. Is this even possible though? <?php if(isset($_POST['submit'])) { $headers = 'From: [email protected]' . "\r\n" . "Reply-To: '$email'" . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $to = "[email protected]"; $subject = "Contact Form"; $firstname_field = $_POST['first']; $lastname_field = $_POST['last']; $email_field = $_POST['email']; $phone_field = $_POST['phone']; $order_field = $_POST['ordernum']; $topic_field = $_POST['topic']; $comments = $_POST['comments']; $body = " From: $firstname_field $lastname_field\n\n E-Mail: $email_field\n\n Phone #: $phone_field\n\n Order #: $order_field\n\n Topic: $topic_field\n\n Comments: $comments"; header ("Location: http://www.ryanbuening.com/thankyou.html"); mail($to, $subject, $body, $headers); } else { echo "Error!"; } ?> Link to comment https://forums.phpfreaks.com/topic/192989-php-mailer-from-nobody/#findComment-1016368 Share on other sites More sharing options...
mapleleaf Posted February 22, 2010 Share Posted February 22, 2010 Put the $email in the FROM and I think you need to remove the ' from either side of $email. Also the you need to set the $email variable before adding it to the $headers Link to comment https://forums.phpfreaks.com/topic/192989-php-mailer-from-nobody/#findComment-1016432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.