0

Here When I am sending the mail through phpmailer, username testname get on mail. However I want testname to be displayed. What I understand from the phpmailer is the $mail->Username and $mail->Password is required to authentication and $mail->Username is also used at envelope mail. Is there any way to change testname to testname. And I also tried to set $mail->Sender, still not working. I know I am doing some silly mistake here, but I am stuck here now. Any help will be appreciated. Thanks in advance.

    $mail->Username   = 'xyz@gmail.com';
    $mail->Password   = 'xxxxx';
    $name='testname';

    $mail->SetFrom('testmail.com', $name, true);

    $mail->AddReplyTo('no-reply@mycomp.com','no-reply');
    $mail->Subject    = 'subject';
    $mail->MsgHTML($body);

    $mail->AddAddress('xyz@gmail', 'title1');
    //$mail->AddAddress('abc2@gmail.com', 'title2'); /* ... */
    $fileName='../rough/test.pdf';
    $mail->AddAttachment($fileName);
Nitu Dhaka
  • 1,300
  • 3
  • 14
  • 29

2 Answers2

1

Try adding:

$mail->From = 'sender@senderdomain.com';
$mail->FromName = 'Sender Name';

Also, as Selvin pointed out, gmail is known to rewrite the headers to change the sender info on messages sent through gmail, so that the sender matches the user associated with the gmail account that the message is sent through. See How to change from-address when using gmail smtp server for more info.

Community
  • 1
  • 1
mti2935
  • 11,465
  • 3
  • 29
  • 33
0

If u are send mail from gmail id to another gmail id using PHPmailer gmail assigns the authenticated user id xyz@gmail.com as the sender instead of testmail.com and save contact name for xyz@gmail.com instead testname

try sending mail to some other provider

Selvin
  • 180
  • 1
  • 7