PHPMailer SMTP Auth错误:无法进行身份验证

时间:2015-10-17 14:47:54

标签: php email phpmailer smtp-auth

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

PHPMailer 5.2.13

PHP Version 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已启用。

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

1 个答案:

答案 0 :(得分:0)

这是我的工作示例,也许可以帮到你:

$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
}