无法发送信息。邮件错误:SMTP错误:无法验证

时间:2018-12-02 13:37:31

标签: php mysql

我在为我的网站注册帐户时遇到了问题,我不明白这是什么问题。

require 'vendor/autoload.php';

                $mail = new PHPMailer(true);                             
                try {
                    //Server settings
                    $mail->isSMTP();                                     
                    $mail->Host = 'smtp.gmail.com';                      
                    $mail->SMTPAuth = true;                               
                    $mail->Username = 'testsourcecodester@gmail.com';     
                    $mail->Password = 'mysourcepass';                    
                    $mail->SMTPOptions = array(
                        'ssl' => array(
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                        'allow_self_signed' => true
                        )
                    );                         
                    $mail->SMTPSecure = 'ssl';                           
                    $mail->Port = 465;                                   

                    $mail->setFrom('testsourcecodester@gmail.com');

                    //Recipients
                    $mail->addAddress($email);              
                    $mail->addReplyTo('testsourcecodester@gmail.com');

                    //Content
                    $mail->isHTML(true);                                  
                    $mail->Subject = 'ECommerce Site Sign Up';
                    $mail->Body    = $message;

                    $mail->send();

                    unset($_SESSION['firstname']);
                    unset($_SESSION['lastname']);
                    unset($_SESSION['email']);

                    $_SESSION['success'] = 'Account created. Check your email to activate.';
                    header('location: signup.php');

                } 
                catch (Exception $e) {
                    $_SESSION['error'] = 'Message could not be sent. Mailer Error: '.$mail->ErrorInfo;
                    header('location: signup.php');
                }


            }
            catch(PDOException $e){
                $_SESSION['error'] = $e->getMessage();
                header('location: register.php');
            }

            $pdo->close();

        }

    }

}
else{
    $_SESSION['error'] = 'Fill up signup form first';
    header('location: signup.php');
}

?>

0 个答案:

没有答案