使用PHP Swift Mailer v 5.4.9并设置以下from
可行:
$transport = (new Swift_SmtpTransport($host, $port, 'ssl'))->setUsername($user)->setPassword($pass);
$mailer = new Swift_Mailer($transport);
$message = (new Swift_Message($subject))->setBody($body['message'], $body['content_type']);
$message->setFrom(['no-reply@test.com']);
但是设置此from
无效:
$transport = (new Swift_SmtpTransport($host, $port, 'ssl'))->setUsername($user)->setPassword($pass);
$mailer = new Swift_Mailer($transport);
$message = (new Swift_Message($subject))->setBody($body['message'], $body['content_type']);
$message->setFrom(['no-reply@testtesttest.com]);
这是怎么回事?为什么@
符号后的长域名不起作用?它似乎停止发送大约10个字符的电子邮件。我的组织机构的名称很长(my-organization.com),我希望为要发送的这些电子邮件指定完整的名称。
似乎在第85行的Swift_RfcComplianceException
vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php
中抛出了send
,我试图从该异常中检索消息并得到空字符串。
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
$failedRecipients = (array) $failedRecipients;
if (!$this->_transport->isStarted()) {
$this->_transport->start();
}
$sent = 0;
try {
$sent = $this->_transport->send($message, $failedRecipients);
} catch (Swift_RfcComplianceException $e) {
foreach ($message->getTo() as $address => $name) {
$failedRecipients[] = $address;
}
}
return $sent;
}