gpt4 book ai didi

mysql - Symfony2.2 Swiftmailer 无法在 AWS-EC2 服务器站点中工作

转载 作者:行者123 更新时间:2023-11-30 01:31:00 25 4
gpt4 key购买 nike

我正在开发一个 symfony 2.2 项目站点,在该站点中我使用 swift mailer 来发送邮件;在 Parameter.yml 中,配置如下:

database_driver:   pdo_mysql
database_host: localhost
database_port: null
database_name: My_Project_Name
database_user: username
database_password: userpass

mailer_transport: gmail
mailer_host: smtp.gmail.com
mailer_encryption: ssl
mailer_auth_mode: login
mailer_user: my_user_name@gmail.com
mailer_password: my_gmail_account_password

locale: en
secret: my_secret
database_path: null

我的邮件如下:

       $message = \Swift_Message::newInstance()
->setSubject("Subject_description")
->setFrom("my_user_name@gmail.com")
->setTo("destination_email@maildomain.com")
->setBody("message_body");

$this->mailer->send($message);

它在本地主机中运行良好,但是当项目站点在AWS-EC2服务器上运行时,它没有给出任何错误,并给出有关成功完全发送邮件的通知消息,但实际上在destination_email@maildomain.com上没有收到电子邮件。我不知道我的配置有什么问题?

如果有人对此问题有任何想法,请告诉我,我们将不胜感激!

最佳答案

通过许多帮助链接提取我的想法后,我终于找到了如下所示的解决方案:

# app/config/parameter.yml
swiftmailer:
transport: smtp
host: email-smtp.us-east-1.amazonaws.com
username: AWS_ACCESS_KEY
password: AWS_SECRET_KEY
encryption: tls
port: 25

在邮件中:

 $renderedLines = explode("\n", trim($renderedTemplate));
$subject = $renderedLines[0];
$body = implode("\n", array_slice($renderedLines, 1));
$transport = \Swift_SmtpTransport::newInstance( 'email-smtp.us-east-1.amazonaws.com',
25,
'tls')->setUsername('aws_key')->setPassword('aws_secret');
$innerMailer = \Swift_Mailer::newInstance($transport);
$message = \Swift_Message::newInstance()
->setSubject('My_Project_Title_Subject')
->setFrom(array('my_mail@domail.com' => 'Reference Name'))
->setTo("destination_mail@domail.id")
->setBody($body, 'text/html');

$innerMailer->send($message);

终于可以工作了!

希望它能帮助别人!

关于mysql - Symfony2.2 Swiftmailer 无法在 AWS-EC2 服务器站点中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17464243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com