【发布时间】:2016-05-28 04:48:01
【问题描述】:
我知道这个问题已经有很多答案,例如this,但似乎没有一个解决方案适合我。
我正在尝试从我的 Google Apps 域发送电子邮件。大部分时间都在发送电子邮件,但有时会引发此异常并且电子邮件不会发送。
Uncaught PHP Exception Swift_TransportException: "Expected response code 220 but got code "", with message """ at C:\HostingSpaces\abc\domain.com\wwwroot\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php line 383 {"exception":"[object] (Swift_TransportException(code: 0): Expected response code 220 but got code \"\", with message \"\" at C:\\HostingSpaces\\abc\\domain.com\\wwwroot\\vendor\\swiftmailer\\swiftmailer\\lib\\classes\\Swift\\Transport\\AbstractSmtpTransport.php:383)"} []
是的,我使用 SSL,是的,我已授予对安全性较低的应用程序的访问权限,是的,我使用端口 465。我已启用假脱机,这样应用程序就不会因为异常未被捕获而崩溃。
我的 config.yml 在下面
swiftmailer:
transport: smtp
host: smtp.gmail.com
username: no-reply@googledomain.com
password: password
port: 465
encryption: ssl
spool: { type: memory }
我的电子邮件课程在下面
public function send_new_order_email($entity) {
try{
$message = $this->getEmailObj("toaddress@gmail.com");
$message->setBody(
$this->renderView(
'APIBundle:Emails:ops_neworder.html.twig',
array('entity' => $entity)
),
'text/html'
)->setSubject('New Order : '.$entity->getId());
$this->container->get('mailer')->send($message);
}
catch(Exception $e){}
}
private function getEmailObj($email){
$message = \Swift_Message::newInstance()
->setFrom('no-reply@googledomain.com')
->setTo($email);
return $message;
}
您对这项工作有什么建议吗?
【问题讨论】:
标签: php symfony smtp gmail swiftmailer