今天在bluehost的服务器上,开发一个群发功能,当时使用的是smtp.163.com 结果就报了以下错误.
could not connect to SMTP host
除了bluehost外,其他国外主机也有类似问题.
public function mail($recive,$title,$content) {
header('Content-type:text/html;charset=utf-8');
vendor("PHPMailer.class#phpmailer"); //从PHPMailer目录导入class.phpmailer.php类文件
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
// $mail->Host = "smtp.qq.com"; // SMTP server 部分邮箱不支持SMTP,QQ邮箱里要设置开启的
$mail->SMTPDebug = false; // 改为2可以开启调试
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "localhost"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->CharSet = "UTF-8"; // 这里指定字符集!解决中文乱码问题
$mail->Encoding = "base64";
$mail->Username = "cory+cazhaopin.com"; // SMTP account username
$mail->Password = "54235465"; // SMTP account password
$mail->AddAddress($recive, 'Dear customer');
$mail->SetFrom('cory@cazhaopin.com', 'CA招聘网'); //发送者邮箱
$mail->AddReplyTo('cory@cazhaopin.com', 'CA招聘网'); //回复到这个邮箱
$mail->Subject = $title;
$body = $content;
$mail->MsgHTML($body);
//$mail->AddAttachment('images/phpmailer.gif'); // attachment
// $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
$mail->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
}
在这里 www.cazhaopin.com是 域名. , $recive是接受文件,$title是标题变量,$content是内容.
bluehost是不允许其他SMTP服务器在它们的host上运行的.
将上面变量 修改下,即可使用, 如果你用的是TP的话,
如果是用PHP源码的话, 记得将host 改成 localhost
用户名 由 cory@cazhaopin.com 改成 cory+cazhaopin.com
端口,自己可以去mail account里的 more configrue email client 里看就知道了.
其他就不必做什么改动了
could not connect to SMTP host在bluehost的问题 ,就这样解决了.
本贴出自纽约网站设计,转帖请带链;www.01webs.com