如何使用 Swiftmailer 和 Gmail 设置“FROM"属性?

2022-01-23 00:00:00 email gmail php swiftmailer
<?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);
?>

它有效,但发件人是用户名@gmail.com".如何指定任何其他电子邮件地址以发送虚假电子邮件?

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

推荐答案

Gmail 不允许覆盖 FROM 名称,但您向 gmail 证明您拥有的经过验证的电子邮件地址除外.选择其他电子邮件服务器或转到您的 gmail 设置并将其更改为另一个您可以接收电子邮件的有效电子邮件地址.

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.

相关文章