phpmailer没有发送电子邮件

时间:2011-11-03 16:54:06

标签: php

我正在使用phpmailer,我收到以下错误:

未发送消息 邮件程序错误:SMTP错误:无法连接到SMTP主机。

<?php
require("class.phpmailer.php");
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = 'ssl://smtp.myhost.com:465';
$mailer->SMTPAuth = TRUE;
$mailer->Username = 'myemail@myhost.com';
$mailer->Password = 'mypass';
$mailer->From = 'myemailagain@myhost.com';
$mailer->FromName = 'myname';
$email1 = $_GET['email'];
$verification = rand();
$mailer->Body = 'Welcome to our site';
$mailer->Subject = 'verification';
$mailer->AddAddress($email1);
if(!$mailer->Send())
{
   echo "Message was not sent<br/ >";
   echo "Mailer Error: " . $mailer->ErrorInfo;
}
else
{
   echo "Message has been sent";
}
?> 

注意:我使用“myhost.com”,但这不是我的真实域名

1 个答案:

答案 0 :(得分:4)

我相信你错误地指定了你的主机。试试这个:

$mailer->Host="smtp.myhost.com";
$mailer->Port=465;
$mailer->SMTPSecure="ssl"; //If this doesn't work, try 'tls'

如果仍然无效,请考虑设置:

$mailer->SMTPDebug=1;

另外,请确保已启用PHP的OpenSSL扩展。