尝试使用PHPMAILER发送电子邮件时出错

时间:2022-08-12 18:14:50

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

if(empty($errors)) {
        $mail = new PHPMailer;
        $mail->isSMTP();
        $mail->SMTPAuth = true;
        $mail->Host = 'smtp.gmail.com';
        $mail->Username = 'o.rostom.93@gmail.com';
        $mail->Password = 'XXXXXX'; 
        $mail->SMTPSecure = 'ssl';
        $mail->Port = 465;
        $mail->FromName = $fields['fname'] . ' ' . $fields['lname'];
        $mail->addAddress('o.rostom.93@hotmail.com','Omar Khairy');
        $mail->Body = $fields['message'];
        if(!$mail->Send()) {
           echo $mail->ErrorInfo;
        } else {
            echo "NON";
        }
    }

I have tried manuplating ports, SMTP Secures, nothing is getting better, I have enabled POP and Imap from the gmail, I have also turned on less secure apps, nothing, thanks in advance.

我已经尝试过设备端口,SMTP安全,没有什么变得越来越好,我已经从gmail启用了POP和Imap,我也开启了不太安全的应用程序,没有,提前感谢。

1 个解决方案

#1


Try using

$mail->SMTPSecure = "tls";              
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 587;

#1


Try using

$mail->SMTPSecure = "tls";              
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 587;