无法发送信息。邮件错误:XAMPP

时间:2019-11-12 04:20:28

标签: php phpmailer

我尝试过 通过在PHP.ini中取消注释extension = php_openssl.dll来启用openSSL 但仍然出现相同的错误,

  

无法发送消息。邮件错误:SMTP connect()失败   XAMPP

我该怎么办?

if ($_POST) {
$email = $_POST['email'];

$selectquery = mysqli_query($connection, "SELECT * from tb_user where email = '{$email}'") or die(mysqli_error(connection));
$count = mysqli_num_rows($selectquery);
$row = mysqli_fetch_array($selectquery);

if ($count > 0) {
    // Instantiation and passing `true` enables exceptions
    $mail = new PHPMailer(true);
    try {
        //Server settings

        $mail->isSMTP();                                            // Send using SMTP
        $mail->Host = 'smtp.gmail.com';                   // Set the SMTP server to send through
        $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
        $mail->Username   = 'melvinvois77@gmail.com';                     // SMTP username
        $mail->Password   = '######';                               // SMTP password
        $mail->SMTPSecure = 'tls';         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
        $mail->Port       = 587;                                    // TCP port to connect to

        //Recipients
        $mail->setFrom('melvinvois77@gmail.com', 'Asisten Untar');
        $mail->addAddress("$email");     // Add a recipient
        $mail->addReplyTo('melvinvois77@gmail.com', 'No Replay');


        // Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'Here is the subject';
        $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

        $mail->send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }
}
}

0 个答案:

没有答案