PHP SwiftMailer 本地主机测试设置
我刚刚开始学习如何使用 SwiftMailer 并且我在从本地主机发送简单的测试消息时遇到问题。下面是我尝试使用的代码。
//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]' => 'My Name'));
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 25);
//Supposed to allow local domain sending to work from what I read
$transport->setLocalDomain('[127.0.0.1]');
$mailer = Swift_Mailer::newInstance($transport);
//Send the message
$result = $mailer->send($message);
这是我的错误消息的一部分,
Warning: fsockopen() [<a href='function.fsockopen'>function.fsockopen</a>]:php_network_getaddresses: getaddrinfo failed: Name or service not known in /path/Swift/Transport/StreamBuffer.php
更新
我让它可以使用 gmail 工作。我将 Swift_SmtpTransport 行更改为以下内容,
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername('username')->setPassword('password');
I just started learning how to use SwiftMailer and I am having trouble sending a simple test message from my localhost. Below is the code that I am trying to use.
//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]' => 'My Name'));
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 25);
//Supposed to allow local domain sending to work from what I read
$transport->setLocalDomain('[127.0.0.1]');
$mailer = Swift_Mailer::newInstance($transport);
//Send the message
$result = $mailer->send($message);
Here is part of my error message,
Warning: fsockopen() [<a href='function.fsockopen'>function.fsockopen</a>]:php_network_getaddresses: getaddrinfo failed: Name or service not known in /path/Swift/Transport/StreamBuffer.php
Update
I got it to work using gmail. I changed the Swift_SmtpTransport line to the following,
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername('username')->setPassword('password');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
localhost
是当前计算机的别名(在本例中为运行 PHP 的计算机)。如果您确实想使用本地主机发送邮件,您可以这样说:...但您还需要安装和配置您自己的邮件服务器。如果您不知道这是什么意思,我建议您使用邮件提供商的 SMTP 服务器。
localhost
is an alias for current machine (in this case, the machine PHP runs on). If you really want to send mail with localhost you have say so:... but you also need to install and configure your own mail server. If you don't know what's this all about, I suggest you use your mail provider's SMTP server.