Sender email mismatched with server smtp email

the mail() function

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Mon Apr 02, 2012 3:39 am

Sender email mismatched with server smtp email

Postby connman » Mon Apr 02, 2012 3:51 am

after doing some SMTP email sending testing, I received email from the sender. However, From: header part, the sender email seems to not match with the sender name. Rather it mismatches with the sender name and SMTP server email instead.

This is the code:-

Code: Select all


$name = $_POST['username'];

$email = $_POST['email'];

$text = $_POST['inquiry'];

//To, Subject, Message, Header

//mail('', 'Basic Inquiry', $text, 'From: ' . $name . ' <' . $email . '>');

//header('Location: thanks.php');

$mail             = new PHPMailer();
$body             = $text;
$body             = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth   = true;                        // enable SMTP authentication
$mail->SMTPSecure = "ssl";                       // sets the prefix to the servier
$mail->Host       = "";            // sets GMAIL as the SMTP server
$mail->Port       = 465;                         // set the SMTP port for the GMAIL server
$mail->Username   = "";     // GMAIL username
$mail->Password   = "q1w2e3r4t5";      // GMAIL password
$mail->SetFrom($email, $name);
$mail->Subject    = "Product Enquiry";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$address = "";
$mail->AddAddress($address, "Bill");
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";

and this is the output after receiving email as attached...
is there anyway to fix the mismatch issue? Thanks.

screen.png (27.55 KiB) Viewed 489 times

test is the sender's name btw.

User avatar
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Sender email mismatched with server smtp email

Postby egami » Mon Apr 02, 2012 8:14 am

investigate the headers of the mail.

Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 3 guests