php – 尝试使用SwiftMailer发送带有Symfony 2的电子邮件:无法与主机smtp.gmail.com
|
这里首先描述我的环境,因为它有点特别:
然后,我使用Symfony 2作为我的项目,我正在尝试使用SwiftMailer和gmail(使用我自己的gmail地址),以便通过联系表单(用户的电子邮件地址,用户名和内容)发送电子邮件.邮件). 我的操作使用表单中给出的内容填充电子邮件数据并发送邮件. 我提交表单后出现问题,我从SwiftMailer收到异常:无法与主机smtp.gmail.com [#0]建立连接 这是我的config_dev.yml: swiftmailer:
transport: gmail
username: "%gmail_user%"
password: "%gmail_password%"
delivery_address: "%gmail_user%"
encryption: ssl
host: smtp.gmail.com
port: 465
auth_mode: login
“%gmail_user%”和stuff在parameters.yml文件中定义.这是内容: parameters: mailer_transport: gmail mailer_user: null mailer_password: null gmail_user: my_gmail_address@gmail.com gmail_password: my_gmail_passwd 经过整个互联网的大量搜索,我从这里或其他地方尝试了很多东西,没有任何工作:使用tls,尝试端口587,尝试使用smtp.gmail.com服务器的IP给了我同样的东西错误. SSL扩展似乎也启用了: php --info | grep openssl OpenSSL support => enabled 以及其他一些告诉OpenSSL版本的东西. 我检查了我的IMAP设置和启用或禁用应用程序访问我的Gmail的常规设置,它已启用. 我还试图telnet smtp.google.com 465,自从我联系到它以来它运行良好. 我现在不知道该怎么做.我希望你们中的一些人有同样的问题,可以帮助我. 祝你今天愉快 ! 编辑:问题解决了,出现了一个新问题 经过进一步调查后,我随机尝试以这种方式更改config_dev.yml文件: transport: mail 这解决了SwiftMailerException的问题,尽管邮件没有到达delivery_address电子邮件地址,即使我将其更改为我拥有的另一个地址(一个hotmail). 编辑#2:尝试解决发送问题,但没有任何效果. 这将是一本书.. spool: {type: memory }
邮件似乎是在发送者告诉我他发送邮件之后发送的. $spool = $transport->getSpool();
$sent = $spool->flushQueue($this->container->get('swiftmailer.transport.real'));
我还添加了这个来检查它是否真的发送过: if ($this->mailer->send($message)) {
echo '[SWIFTMAILER] sent email to ' . $toEmail;
} else {
echo '[SWIFTMAILER] not sending email: ' . $mailLogger->dump();
}
我真的迷路了,不知道该怎么办.. 这是在控制器中发送邮件的代码: $message = Swift_Message::newInstance()
->setSubject("The subject from the form")
->setFrom("The address from the form")
->setTo("The address which comes from an entity")
->setBody("The body from the form made with a twig template");
$mailer = $this->container->get('mailer');
$mailLogger = new Swift_Plugins_Loggers_ArrayLogger();
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($mailLogger));
if ($mailer->send($message)) {
echo 'sent email';
} else {
echo 'not sending email: ' . $mailLogger->dump();
}
这总是告诉我“发送电子邮件”,但我从未收到过. 您是否尝试与cURL建立连接?我有类似的弹性搜索(elastica),显然它使用了我不知道的cURL HTTP代理,因为它是在php.ini中配置的.偏离主题:您也可以尝试mailcatcher是否适合您的需求. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
