John
John

Reputation: 1085

PHPmailer gmail 'from' is gmail account

I'm trying to send a mail with PHPmailer and gmail. But when I send a mail its from my gmail account instead of no-reply. How do I set no-reply as from?

Code I have:

$mail = new PHPMailer();  

$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true; 
$mail->Username = "[email protected]"; 
$mail->Password = "password"; 

$mail->From     = "[email protected]";
$mail->AddAddress($to);  
$mail->AddReplyTo("[email protected]","no-reply");

$mail->Subject  = $subject;
$mail->Body     = $msg;
$mail->WordWrap = 150; 
$mail->send();

The mail I get receives (headers):

Return-Path: <[email protected]>

Which should be [email protected]

Thanks in advance

Upvotes: 3

Views: 5128

Answers (2)

Andrew Odri
Andrew Odri

Reputation: 9432

There are two options I would recommend trying:

  1. Log in to the Google Apps mail account for [email protected], go to Settings, then Accounts, then Send mail as, and ensure that [email protected] has been validated. I haven't tested this, but this should allow to send mail from [email protected], rather than from [email protected] on behalf of [email protected].

  2. Actually create a user on Google Apps with the username [email protected], and send email through that account. If [email protected] needs a copy, you could always BCC the address and setup a filter on [email protected] to forward any failures to [email protected].

Upvotes: 5

dev-null-dweller
dev-null-dweller

Reputation: 29462

You can't do it. Just imagine sending mail prompting to reply with your bank account credentials from an address [email protected].

To have no-reply address you must have an access to the mail server in @your.domain (not gmail) and create such account there, then send emails using this account.

Upvotes: 1

Related Questions