2016-07-14 146 views
0

沒有多大意義,爲什麼從字段沒有發送,因爲它應該是。電子郵件'from'字段設置不正確與phpmailer 5.2

這是代碼:

$mail    = new PHPMailer();    

     $mail->IsSMTP(); // telling the class to use SMTP 

     //$mail->SMTPDebug = 1;     
     $mail->SMTPAuth = true;     
     $mail->SMTPSecure = "tsl";     
     $mail->Host  = "smtp.gmail.com"; 
     $mail->Port  = 587;     
     $mail->Username = "[email protected]"; 
     $mail->Password = "***"; 
     $address = "[email protected]"; 
     $mail->AddAddress($address, "Guilherme"); 


     $mail->SetFrom("[email protected]", "from you"); //<------ HERE 
     $mail->AddReplyTo("[email protected]", "reply be"); 


     $mail->Subject = "Email enviado pelo site.";   
     $mail->AltBody = $mensagem;    
     $mail->MsgHTML($mensagem); 

     if(!$mail->Send()) { 
      echo "Mailer Erro: " . $mail->ErrorInfo; 
     } else {  
      echo "Mensagem Enviada!"; 
     } 

電子郵件I'm接受的是:

enter image description here

我使用的是最新版本的PHPMailer 5.2

+0

使用 查詢 $ mail-> From =「[email protected]」; $ mail-> FromName =「Full Name」; 它的工作 –

+0

我很抱歉,但我得到了同樣的結果。從電子郵件被設置爲[email protected] –

+1

無關的問題:你有一個錯字。 「SMTPSecure」應該是「tls'',而不是」tsl''。 – Synchro

回答

1

這不是你的錯 - 你做的都是正確的 - 但你不能這麼做,因爲Gmail不允許你從任意地址發送。你可以做的最好的是在你的gmail首選項中預定義一些別名並使用它們。

這包括在PHPMailer文檔和other questions中。