2015-06-06 23 views
-1

我想從本地服務器發送郵件,但郵件不會在本地發送。錯誤是:郵件不會從本地服務器發送

SMTP Error: Could not authenticate.

<?php 
include_once'mail/class.phpmailer.php'; 
include_once'mail/class.pop3.php'; 
include_once'mail/class.smtp.php'; 
class MailSender{ 
    public static function SendMail($to,$subj,$body,$username){ 
     $mail=new PHPMailer(); 
     $mail->IsSMTP(); 
     //$mail->Host="mail.gmail.com"; 
     $mail->SMTPAuth=true; 
     $mail->SMTPSecure = 'ssl'; 
     $mail->Host="smtp.gmail.com"; 
     $mail->Port=587; 
     $mail->Username="[email protected]"; 
     $mail->Password="fdslkfsd"; 
     $mail->SetFrom('[email protected]','Rahul lodhi'); 
     $mail->Subject=$subj; 
     $mail->MsgHTML($body); 
     $mail->AltBody="to view the msg"; 
     $address=$to; 
     $mail->AddAddress($address,$username); 
     if(!$mail->Send()){ 
      return"Mailer Error :".$mail->ErrorInfo; 
      }else{ 
       return"message sent"; 
       } 
     } 
    } 
?> 
+0

你有沒有嘗試過的東西或搜索有關錯誤的信息? – javierfdezg

+0

是的,但沒有找到正確的解決方案 –

+0

您是否在PHP中啓用了OpenSSL支持?你也定義了兩次主機。 – javierfdezg

回答

2

你應該使用的端口是465(SSL),而不是587(TLS)。

也可以嘗試使用下面的Host值:

$mail->Host = 'ssl://smtp.gmail.com';

+0

我已經試過這個,但它沒有加工 –

相關問題