我想从localhost向gmail发送一封电子邮件,但它说" SMTP connect()失败" 这是我的代码。我还尝试更改配置php.ini和sendmail.ini,但没有运气。 谢谢。
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'asd@gmail.com';
$mail->Password = 'password';
$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('asd@gmail.com');
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = 'Email'
$mail->Body = "This is body";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
答案 0 :(得分:1)
尝试以下内容:
快乐编码:)
答案 1 :(得分:0)
检查$ mail->主题='电子邮件'行是否缺少;