我在使用pear mail包尝试发送邮件时遇到了无尽的麻烦:
我正在使用xampp进行本地测试,以下代码完美地运行:
//PEAR
require_once('../PEAR/Mail.php');
$from = "<sender@domain.com>";
$to = "<receiver@domain.com>";
$subject = "Hi";
$body = "Testing message";
$host = "ssl://smtp.gmail.com"; //ssl://
$port = "465";
$username = "my_account@gmail.com";
$password = "**********";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
function &factory($driver, $params = array())
{
$driver = strtolower($driver);
@include_once 'Mail/' . $driver . '.php';
$class = 'Mail_' . $driver;
if (class_exists($class)) {
$mailer = new $class($params);
return $mailer;
} else {
return PEAR::raiseError('Unable to find class for driver ' . $driver);
}
}
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
//end of php tag
然而,当我将文件上传到在线网站并运行完全相同的脚本时,我收到以下错误信息:
“连接ssl://smtp.gmail.com:465失败[SMTP:连接套接字失败:拒绝连接(代码:-1,响应:)]”
我还尝试了端口587和443,但都没有成功。 我猜问题必须出在socket.php、smtp.php、mail.php甚至服务器配置文件中,因为上述代码似乎没有问题。 如果有人能指点我正确的方向,我将非常感激!
ssl://
? - Treffynnon