Page 1 of 1

PHP Mailer From 'Nobody' ?

Posted: Mon Feb 22, 2010 2:40 pm
by beaner_06
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.

Code: Select all

 
<?php
if(isset($_POST['submit'])) {
 
$to = "ryanbuening@gmail.com";
$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!";
}
?>
 

Re: PHP Mailer From 'Nobody' ?

Posted: Mon Feb 22, 2010 2:54 pm
by AbraCadaver
Yes.

Code: Select all

$from = "From: First Last <somebody@example.com>\r\n";
mail($to, $subject, $body, $from);
In certain circumstances, this may be one, you have to set this before sending:

Code: Select all

ini_set('sendmail_from', 'somebody@example.com');

Re: PHP Mailer From 'Nobody' ?

Posted: Mon Feb 22, 2010 3:13 pm
by beaner_06
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?

Code: Select all

 
<?php
if(isset($_POST['submit'])) {
 
$headers = 
   'From: webmaster@domain.com' . "\r\n" .
   "Reply-To: '$email'" . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
   
$to = "ryanbuening@gmail.com";
$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'];
 
mail($to, $subject, $body, $headers);
}
 
?>
 

Re: PHP Mailer From 'Nobody' ?

Posted: Mon Feb 22, 2010 3:28 pm
by AbraCadaver
Looks fine except for the single quotes around the reply-to address.

Re: PHP Mailer From 'Nobody' ?

Posted: Mon Feb 22, 2010 3:42 pm
by beaner_06
When I make that change, the reply e-mail address looks like: $email@domain.com