How to set 'FROM' property using Swiftmailer with Gmail?

北战南征 提交于 2019-11-28 08:08:23

问题


<?php
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
  ->setUsername('username@gmail.com')
  ->setPassword('password')
  ;
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('HomeWork')
  ->setFrom(array('exampleFROM@gmail.com' => 'NAME'))
  ->setTo(array('exampleTO@gmail.com'=> 'NAME'))
  ->setBody('Test Message Body')
  ;
$mailer->send($message);
?>

It works but sender is 'username@gmail.com'. How can I specify any other email address in order to send fake email?


回答1:


Gmail disallows overriding the FROM name except from verfied email addresses that you prove to gmail you own. Either choose a different email server or go to your gmail settings and change it to another valid email address that you can receive email from.




回答2:


You need to set the outgoing emailaddress in gmail. Gmail changes the emailaddress to the address in your gmail if it is not in the list of emailaddresses where you can sent from.

Gmail -> settings -> Send mail as -> Add another email address you own



来源:https://stackoverflow.com/questions/14128472/how-to-set-from-property-using-swiftmailer-with-gmail

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