Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHPMailer SMTP连接错误_Php_Email_Phpmailer - Fatal编程技术网

PHPMailer SMTP连接错误

PHPMailer SMTP连接错误,php,email,phpmailer,Php,Email,Phpmailer,在过去的几个小时里,我一直在想如何让phpMailer工作。我总是出错。这是我的密码: <?php $name = $_REQUEST['name'] ; $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; require("class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP $mail->

在过去的几个小时里,我一直在想如何让
phpMailer
工作。我总是出错。这是我的密码:

<?php
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

require("class.phpmailer.php");
$mail = new PHPMailer(); 
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "******@gmail.com"; // SMTP username
$mail->Password = "******"; // SMTP password
$host = "smtp.mandrillapp.com";
$port = 587;
$mail->SMTPSecure = 'ssl';  
$mail->SMTPDebug = 1;
$webmaster_email = "****@gmail.com"; //Reply to this email ID
$email= $email; // Recipients email ID
$name= $name; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "University of Life Experiences";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "ULE";
$mail->Body = $message; //HTML Body
$mail->AltBody = $message; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>

您没有设置SMTP主机(尽管您声明了变量
$Host
)。通过以下方式进行设置:

$mail->host = $host;
感谢@Rikesh的提醒,
$port
也是同样的情况

旁注:我注意到你使用gmail.com作为回复邮件,但你的SMTP服务器不是gmail。这可能会导致某些电子邮件服务器将您的电子邮件放入垃圾邮件/垃圾邮件文件夹。

尝试添加以下内容:

$mail->Mailer   = "SMTP"; // SMTP Method

请参阅此链接,尝试更改端口号

$port = 587;

并检查您收到的新错误,我相信您不会再次收到SMTP连接错误

  • 使用SSL:
  • $mail->SMTPSecure='ssl';//启用TLS加密,也接受'ssl'
    $mail->Port=465;//ssl
    
  • 在php文件中添加以下内容:
  • $mail->SMTPOptions=array(
    “ssl”=>数组(
    “验证对等方”=>false,
    'verify_peer_name'=>false,
    “允许自签名”=>true
    )
    );
    
  • myaccount.gmail.com
    登录和安全
    具有帐户访问权限的应用
    设置
    允许安全性较低的应用
    打开

  • 您是否尝试使用本地主机上的smtp?这是您使用
    SMTPDebug=1
    获得的所有信息?您是否使用托管Web服务器?可能防火墙正在阻止端口25。如果您可以通过ssh进行连接,请尝试将您的服务器smtp
    telnet
    并查看发生了什么。您需要将
    host
    ($host)和
    port
    ($port)分配给phpmailer对象。是否尝试将SMTPsecure从ssl更改为tls<代码>$mail->SMTPSecure='tls'$mail->IsSMTP();//通过SMTP发送
    。此外,您提供的链接不是官方文档。
    $port = 465;