Jump to content

Recommended Posts

I'm new to PHP and working on a mailform with phpmailer with attachment. Everything works fine but the received mail keeps having my Gmail address in the from header.

The AddReplyTo address works fine but I don't want to show the gmail address.

 

This is what my code looks like:

 

 


require('C:\xampp\htdocs\PHPMailer\class.phpmailer.php');
 
$mail = new PHPMailer();  // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2;  // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true;  // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465; 
$mail->Username = 'myaccount@gmail.com';  
$mail->Password = 'mypassword'; 
$mail->SetFrom('e-mail@address.com', 'email@address.com');
$mail->AddReplyTo('e-mail@address.com', 'e-mail@address.com');
 
$mail->AddAddress("myaccount@gmail.com", "MyAccount");
$mail->Subject = "TestMail";
$mail->Body    = "This is the message body";
$mail->AddAttachment("test.txt", "test.txt");  // optional name
if(!$mail->Send())
{
   echo "Error";
   exit;
}
else {
echo "OK";
}

 

 

 

I only want to use the gmail smtp but want to show another e-mail address (e-mail@address.com in thie example) in the header. But it keeps showing myaccount@gmail.com.

Also in the class.phpmailer.php I've configurated the $From, $FromName and $Sender as e-mail@address.com but this doesn't work.

 

Can somebody help me with this?

Link to comment
https://forums.phpfreaks.com/topic/285258-phpmailer-from-header/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.