我想从本地服务器发送邮件,但邮件不会在本地发送。错误是:
SMTP错误:无法进行身份验证。
<?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="rahullodhi3636@gmail.com";
$mail->Password="fdslkfsd";
$mail->SetFrom('rahullodhi3636@gmail.com','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 :(得分:2)
您应使用的端口是465
(SSL),而不是587
(TLS)。
还尝试使用以下主机值:
$mail->Host = 'ssl://smtp.gmail.com';