Swiftmailer 在本地主机上工作但不在生产中
在我的本地主机(Linux Mint OS)上,Swiftmailer 使用以下代码可以正常工作,但是每当我将其移动到我的服务器时,它就会挂在发送功能上,然后给我一个内部服务器错误。
我目前通过 Google Apps 设置电子邮件,所以 SMTP 可能不适用于这种情况?如果是这样,您建议我如何从 SMTP 更改此设置。
另外,每当我发送这样的电子邮件时,它都会显示用户名区域中的发件人地址。我希望它与“setFrom”函数中的发件人地址一起显示。
//Include the swiftmailer class
require_once 'comm/swiftmailer/swift_required.php';
//Create a message
//Pass it as a parameter when you create the message
$message = Swift_Message::newInstance();
$message->setSubject('My Subject');
$message->setFrom(array('[email protected]' => 'No Reply'));
$message->setTo(array('[email protected]' => 'Me'));
$message->setBody($emailContent, 'text/html');
//Create transport class and email the message
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername('useracctname')->setPassword('password');
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
非常感谢您的帮助!
On my localhost (Linux Mint OS) Swiftmailer is working fine with the following code, but whenever I move it up to my server is just hangs at the send function and then gives me an internal server error.
I currently have my email setup through Google Apps, so maybe SMTP will not work for this situation? If thats the case, how do you suggest I change this from SMTP.
Also, whenever I send an email like this, it is showing up with a from address of the one in the username area. I want it to show up with the from address in the "setFrom" function.
//Include the swiftmailer class
require_once 'comm/swiftmailer/swift_required.php';
//Create a message
//Pass it as a parameter when you create the message
$message = Swift_Message::newInstance();
$message->setSubject('My Subject');
$message->setFrom(array('[email protected]' => 'No Reply'));
$message->setTo(array('[email protected]' => 'Me'));
$message->setBody($emailContent, 'text/html');
//Create transport class and email the message
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername('useracctname')->setPassword('password');
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);
Thanks a lot for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能是服务器上的端口问题。可以关闭端口 465 以防止垃圾邮件。也可能是服务器的 PHP 版本缺乏 SSL 支持。
如果您像您一样明确地寻址 gmail,则您不太可能使用其他传输类型或不同的服务器。
我认为 SMTP 是让它与 Gmail 一起运行的唯一选择。但是,您的服务器可能正在提供基于
mail()
的服务(显然,发件人地址与 GMail 不同)。在这种情况下,您也许可以使用 Swiftmailer 的邮件
传输。This might be a port problem on the server. Port 465 could be closed to prevent spamming. It could also be that the server's version of PHP lacks SSL support.
If you address gmail as explicitly as you do, it's very unlikely you're using another transport type or a different server.
I think SMTP is your only option to get it running with Gmail. It could, however, be that your server is providing a
mail()
based service (obviously with a different sender address than GMail though). In that case, you may be able to use Swiftmailer'smail
transport.我遇到了同样的问题:我能够在本地发送 gmail 电子邮件(更新配置后:https: //www.google.com/settings/security/lesssecureapps )但不在生产中。
为了解决我的问题,我从我的生产服务器使用我的生产 IP 登录到我的 Gmail 帐户并回答 gmail 安全问题。
使用生产 IP 登录 Gmail 帐户的解决方案之一是
Symfony 输出的错误是:
I had the same problem : I was able to send gmail email in local (after updating that configuration : https://www.google.com/settings/security/lesssecureapps ) but not in production.
To fix my problem I've logged to my gmail account with my production ip / from my production server and answer the gmail security question.
One of the solution to log to your gmail account with your production ip, is to
The error outputed by Symfony was :
好吧,这是解决方案。
如果您要发送 SMTP 邮件,您应该在服务器上创建电子邮件帐户,然后在您的代码中使用此电子邮件信息。
如果您没有有效的电子邮件帐户来使用它发送电子邮件,服务器将不会发送电子邮件
当你使用“来自”时。
这应该是一个真实的、正确的电子邮件帐户,而不是一个假的。
使用假帐户发送的唯一可能原因是使用 mail() 函数。
well, here is the solution.
if you are sending SMTP mail you should create email account at the server then use this email info at your code.
the server will not send the email if you don't have valid email account to send using it
when you use "from".
this should be a true correct email account a fake one.
the only possible reason to send using fake account is using mail() function.