2015-10-17 80 views
0

这是我的基于PHPMailer的我的电子邮件系统的代码。 而且我有一个SMTP验证错误,尝试了很多来自stackoverflow的解决方案,检查并重新检查每个细节,密码,电子邮件。 但从我的角度来看,这可能是一个简单的错误。PHPMailer SMTP身份验证错误:无法验证

PHPMailer的5.2.13

PHP版本5.3.10-1ubuntu3.20

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

include_once("PHPMailerAutoload.php"); 

$para  = "[email protected]"; 
$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 = "[email protected]"; 
    $mail->Password = "password"; 

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

我试图更新更新我的PHPMailer,检查OpenSSL是启用。

经过服务器端口和地址,我想在服务器上使用no-回复电子邮件登录和工作正常

+1

集'$ MAIL-> SMTPDebug'到'2'并检查信息是怎么回事。 '$ mail-> SMTPDebug = 2;' – Mubin

+0

密码命令失败。 现在更改为Gmail,并正常工作,但我试图用我的smtp服务器来解决这个问题。 – Darknessxk

+0

http://stackoverflow.com/questions/20562015/phpmailer-smtp-error-ehlo-command-failed – Mubin

回答

0

这是我工作的例子,也许可以帮助你:

$strTo = array("[email protected]"); 

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 
}