Jump to content

PHP Mailer From 'Nobody' ?


beaner_06

Recommended Posts

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

<?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  ;)

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!";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.