2014-03-07 58 views
0
$mail = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 587; 
$mail->SMTPSecure = 'tls'; 
$mail->SMTPAuth = true; 
$mail->Username = "[email protected]"; 
$mail->Password = "****"; 
$mail->setFrom('[email protected]','duy tran'); 

在收到的電子郵件中顯示來自:duytran gmail。 這意味着它使用用戶名作爲來自email.must是來自:duytran gmail 任何建議解決它?錯誤從郵件收到時

+0

CLIENT - > SMTP:AUTH LOGIN CLIENT - > SMTP:ZWxpbmV4dC5waHBAZ21haWwuY29t CLIENT - > SMTP:OEhiZTYyQ2Y = CLIENT - > SMTP:MAIL FROM:<[email protected]> SMTP - > FROM SERVER:250 2.1.0 OK x5sm31545701pbw.26 - gsmtp – duytran31187

+0

儘量不要添加正確的電子郵件。 – 09stephenb

回答

0

你可以參考這個代碼它會幫助你使用PHP梅勒類

  $mail = new PHPMailer(); 
      $to = "[email protected]"; 
      $mail->IsSendmail(); // telling the class to use SendMail transport 

       $from = $email; 
       $headers = "From: <".$from.">\n"; 
       $headers .= "X-Sender: yourname<".$from.">\n"; 
       $headers .= "X-Mailer: PHP\n"; // mailer 
       $headers .= "X-Priority: 1\n"; // Urgent message! 
       $headers .= "Return-Path: ".$from."\n"; // Return path for errors 
       $headers .= "MIME-Version: 1.0\r\n"; 
       $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; // Mime type 
       $mailBody = ""; 
       $mailBody = '<table cellpadding="4" cellspacing="0" border="0"> 
           <tr> 
            <td valign="top" width="90px;"> 
             <span>Listing For:</span> 
            </td> 
            <td valign="top"> 
             '.$businessDetail['companyName'].' 
            </td> 
           </tr> 
           <tr> 
            <td valign="top" width="90px;"> 
             <span>Listing Url:</span> 
            </td> 
            <td valign="top"> 

            </td> 
           </tr> 
           <tr> 
            <td valign="top" width="90px;"> 
             <span>Email:</span> 
            </td> 
            <td valign="top"> 
             '.$email.' 
            </td> 
           </tr> 
           <tr> 
            <td valign="top" width="90px;"> 
             <span>userName:</span> 
            </td> 
            <td valign="top"> 
             '.$businessDetail['userName'].' 
            </td> 
           </tr> 
           <tr> 
            <td valign="top" width="90px;"> 
             <span>Comment:</span> 
            </td> 
            <td valign="top"> 
             '.$commentDesc.' 
            </td> 
           </tr> 
          </table>'; 

       $mail->Subject = $mailSub; 
       $mail->IsHTML(true); 
       $mail->MsgHTML($mailBody); 
       $mail->SetFrom($email,'yourname'); 
       $mail->AddAddress($to); 

       if($mail->Send()){ 
       $variables['success'] = "posted successfully and email is send."; 
       } 
+0

感謝,但與您的代碼,它不會發送郵件 – duytran31187

+0

請適當調試它,因爲它與我的系統工作正常。我想你錯過了一些代碼。 – Ricky

+0

非常感謝Ricky – duytran31187

相關問題