无法连接到SMTP服务器(PHPmailer)
问题描述:
我有一个网站设置为使用PHPmailer将网站发送到同一个域的电子邮件地址,但我无法获得它连接到SMTP服务器。无法连接到SMTP服务器(PHPmailer)
这是对我的邮件配置文件的一部分:
$config = (object) array();
$config->email_from_addr = "[email protected]";
$config->email_host = "mail.mywebsite.com";
$config->email_from_password = '********';
$config->email_from_name = "Title";
$config->email_to = '[email protected]';
$config->email_subject = "Contact email from mywebsite";
用于发送电子邮件的PHP是在这里:
$phpmailer = new PHPMailer();
$phpmailer->IsSMTP(); // set mailer to use SMTP
if($config->use_gmail == true)
{
$phpmailer->Port = 465;
$phpmailer->Host = "smtp.gmail.com";
}
else
{
$phpmailer->Host = $config->email_host; // specify main and backup server
}
$phpmailer->SMTPAuth = true; // turn on SMTP authentication
$phpmailer->Username = $config->email_from_addr; // SMTP username
$phpmailer->Password = $config->email_from_password; // SMTP password
$phpmailer->From = $config->email_from_addr;
$phpmailer->FromName = $config->email_from_name;
$phpmailer->AddAddress($config->email_to);
$phpmailer->WordWrap = 80; // set word wrap to 80 characters
$phpmailer->IsHTML(true); // set email format to HTML
$phpmailer->Subject = $config->email_subject;
$phpmailer->Body = $message;
$phpmailer->AltBody = $message;
?>
<div style="float:left; display:block; background:#F1F1F1; margin:26px 0 60px 10px; height:200px; padding-top:140px; width:330px; text-align:center; font-size:16px; font-weight:bold" class="red">
<?php
if(@!$phpmailer->Send())
{
?>
<br />
<br />
Your email could not be sent.
<?php
}
else
{
?>
Your email has been sent. Someone will reply to it shortly.
<?php
我只是不知道为什么它不连接到我的邮件服务器。或者,也许我做错了什么。
答
尝试if(!(@$phpmailer->Send()))
代替if(@!$phpmailer->Send())
添加$ phpmailer-> SMTPDebug = 1;并让我们知道您收到什么讯息/错误。 – 2012-08-03 15:21:23
同时关闭邮件发送线上的错误抑制'@',您不会抑制任何错误。 – 2012-08-03 15:23:47
我得到了“SMTP - >错误:无法连接到服务器:连接被拒绝(111)” – SSaaM 2012-08-03 15:24:57