PHP Mailer From 'Nobody' ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
beaner_06
Forum Newbie
Posts: 13
Joined: Tue May 19, 2009 6:11 pm

PHP Mailer From 'Nobody' ?

Post 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!";
}
?>
 
Attachments
nobody.png
nobody.png (7.75 KiB) Viewed 431 times
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP Mailer From 'Nobody' ?

Post 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');
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
beaner_06
Forum Newbie
Posts: 13
Joined: Tue May 19, 2009 6:11 pm

Re: PHP Mailer From 'Nobody' ?

Post 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);
}
 
?>
 
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP Mailer From 'Nobody' ?

Post by AbraCadaver »

Looks fine except for the single quotes around the reply-to address.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
beaner_06
Forum Newbie
Posts: 13
Joined: Tue May 19, 2009 6:11 pm

Re: PHP Mailer From 'Nobody' ?

Post by beaner_06 »

When I make that change, the reply e-mail address looks like: $email@domain.com
Post Reply