2015-06-06 24 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

我已经试过这个,但它没有加工 –

相关问题