【问题标题】:PHPMailer SMTP Auth Error: could not authenticatePHPMailer SMTP 验证错误:无法验证
【发布时间】:2016-01-16 05:36:15
【问题描述】:

这是我基于 PHPMailer 的网站中电子邮件系统的代码。 而且我的 SMTP 出现身份验证错误,尝试了 stackoverflow 的许多解决方案,检查并重新检查了每个细节、密码、电子邮件。 但对我来说可能是一个简单的错误。

PHPMailer 5.2.13

PHP 版本 5.3.10-1ubuntu3.20

并使用我的虚拟主机 SMTP 服务

include_once("PHPMailerAutoload.php");

$para       = "testTarget@domain";
$nome       = $_POST['nome'];
$email      = $_POST['email'];
$telefone   = $_POST['telefone'];
$assunto    = $_POST['assunto'];
$msg        = $_POST['msg'];
$mail       = new PHPMailer(true);
$pop        = new POP3();
$msg_final  = "";

//MSG Build
$msg_final .= "Telefone: ".$telefone."\n\n<br />";
$msg_final .= "Assunto: ".$assunto."\n\n<br />";
$msg_final .= "Email: ".$email."\n\n<br /><br />";
$msg_final .= $msg;

try{
    $mail->SetFrom($email, $nome);
    $mail->AddReplyTo($email, $nome);

    $mail->Subject = $assunto;
    $mail->MsgHTML($msg_final);

    $mail->AddAddress($para, "Central Pires");

    $mail->CharSet = 'UTF-8';

    //Doesnt work anyway
    $pop->Authorise('imap.server', 143, 30, 'no-reply=server', 'pass', 0);

    $mail->IsSMTP();
    $mail->Host = "smtp.hostserver.domain";
    $mail->SMTPSecure = "tls"; //ssl
    $mail->SMTPDebug = 0;
    $mail->SMTPKeepAlive = true; 
    $mail->SMTPAuth = true;
    $mail->Port = 587; //or 465
    $mail->Username = "no-reply@hostserver.domain";
    $mail->Password = "password";

    $mail->Send();
} catch (phpmailerException $e) {
    echo $e->errorMessage();
} catch (Exception $e) {
    echo $e->getMessage();
}

我尝试更新我的 PHPMailer,检查 OpenSSL 是否已启用。

检查了服务器端口和地址,我尝试使用服务器上的无回复电子邮件登录并正常工作

【问题讨论】:

  • $mail-&gt;SMTPDebug 设置为2 并查看信息。 $mail-&gt;SMTPDebug = 2;
  • 密码命令失败。现在改成 gmail 并且工作正常,但我正在尝试用我的 smtp 服务器解决这个问题。
  • 启用调试,如@MubinKhalid 所说,并告诉我们那里显示的确切错误。
  • 您为什么要在 IMAP 端口上执行 POP-before-SMTP?鉴于您也在通过 SSL 进行常规身份验证,为什么还要尝试这样做?

标签: php email phpmailer smtp-auth


【解决方案1】:

这是我的工作示例,可能对您有所帮助:

$strTo = array("test@test.com");

require 'PHPMailer/PHPMailerAutoload.php';
$email = new PHPMailer();
$email->From      = $email_from;
$email->FromName  = $name;
$email->Subject   = $subject;
$email->Body      = $body;
$email->AddReplyTo($email_from, $name);

foreach($strTo as $receiver){
    $email->AddAddress( $receiver );
}
if(isset($_FILES['fileAttach'])){
    $name_file = $_FILES['fileAttach']['name'];
    $path_file  = $_FILES['fileAttach']['tmp_name'];

    $email->AddAttachment( $path_file ,$name_file );
}

$flgSend = $email->Send();
if($flgSend)  
{
    //success
}else{
    //error
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-26
    • 2017-08-19
    • 2016-07-14
    • 2018-08-04
    • 2018-11-13
    • 2015-07-23
    • 1970-01-01
    相关资源
    最近更新 更多