【发布时间】:2011-02-05 09:54:48
【问题描述】:
我使用以下代码发送消息:
try
{
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
$smtp =& new Swift_Connection_SMTP("mail.somedomain.net", 587);
$smtp->setUsername("username");
$smtp->setpassword("password");
$swift =& new Swift($smtp);
//Create the sender from the details we've been given
$sender =& new Swift_Address($email, $name);
$message =& new Swift_Message("message title");
$message->attach(new Swift_Message_Part("Hello"));
//Try sending the email
$sent = $swift->send($message, "$myEmail", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
if($sent)
{
print 'sent';
}
else
{
print 'not sent';
}
}
catch (Exception $e)
{
echo"$e";
}
问题是它在我的本地服务器(我的 xampp 服务器)上运行良好,但在文件上传到真实服务器时无法运行。
它抛出这个错误:
'The SMTP connection failed to start [mail.somedomain.net:587]: fsockopen returned Error Number 110 and Error String 'Connection timed out''
请问我应该怎么做才能纠正这个错误。感谢阅读
【问题讨论】:
-
谢谢,我的主机名是正确的,因为脚本仍在我的计算机(本地 apache 服务器)上时一切正常。请问有什么建议吗?
标签: php swiftmailer