Google App-Gmail Unable to set from. Gmail replacing from address when sending via swiftmailer SMTP transport (PHP)

风格不统一 提交于 2019-12-12 11:56:46

问题


Hello and thank you for any help in advance.

I'm using swiftmailer, SMTP transport method to send email from my PHP script.

Sending the message is fine. It works.

The problem is, no matter what I set the FROM,REPLYTO,SENDER settings to, The email comes through as the GMAIL mailbox (ME - me@mydomain.com) instead.

$transport = Swift_SmtpTransport::newInstance('imap.gmail.com', 465,'ssl')
    ->setUsername($login)
    ->setPassword($password)
    ;
$message = Swift_Message::newInstance($subject)
    ->setFrom(array('test@testdomain.com' => 'test mcttest'))
    ->setReplyTo(array('test@testdomain.com' => 'test mcttest'))
    ->setSender('test@testdomain.com')
    ->setTo(array($to))
    ->setBody(wordwrap($body, 70))
    ->setContentType('text/plain')
    ;

So the email goes through fine, but instead of being from TEST-test@testdomain.com as the sender... it's ME-me@mydomain.com

I switch to a separate (non-gmail) SMTP server to test and the email went through fine, without any problems... definitely think it's a GMAIL thing.

Anyone know how to get around this?


回答1:


Yes, it is Gmail that changes the sender e-mail address to be the same of the account you are authenticating. There is no workaround for that, except maybe becoming a paid customer of Google Apps.




回答2:


Funnily enough I've come across the same issue. But as a bit of an insight, I think this is actually a Swiftmailer issue.

There are other libraries and frameworks (Codeignitor pops in my head) that will let you use Googlemails SMTP servers while masking the from address as an email address of your choosing.



来源:https://stackoverflow.com/questions/4954725/google-app-gmail-unable-to-set-from-gmail-replacing-from-address-when-sending-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!