2015-10-17 83 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 
}