PHPMailer 无法工作 000webhost

标签 php email ssl

我在我的帐户上启用了不太安全的应用程序,但仍然是相同的错误。 无法发送邮件。邮件程序错误:SMTP connect() 失败 我尝试使用免费主机 000webhost。这是我的代码


    require 'PHPMailerAutoload.php';

    $mail = new PHPMailer;

    //$mail->SMTPDebug = 3;                               // Enable verbose debug output

    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'leets@gmail.com';                 // SMTP username
    $mail->Password = 'private';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to

    $mail->setFrom('leets@gmail.com', 'tEst');
    $mail->addAddress('leets@gmail.com');     // Add a recipient
    $mail->addAddress('ellen@example.com');               // Name is optional
    $mail->addReplyTo('info@example.com', 'Information');
    $mail->addCC('cc@example.com');
    $mail->addBCC('bcc@example.com');

    $mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'Hello ,Click On the link to reset password';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
    ?>

请帮助。

最佳答案

更改为 587 端口有帮助吗?

smtp.Host = "smtp.gmail.com"; smtp.Port = 587;

关于PHPMailer 无法工作 000webhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43020791/

相关文章:

iphone - iOS 邮件核心 : How can i download mail attachments and show it in a webview?

validation - 我怎样才能输入一个包含@和.com的电子邮件并让我注册

java - 如何解决 SSL "bad record MAC"异常

php - AJAX 响应和 PHP 循环

php - 有关如何以编程方式为每个项目生成唯一 key 代码的问题?

javascript - 如何使用ajax从一组函数中调用单个函数?

php - CURLOPT_USERPWD 数据在通过 ssl 传输时是否安全?

php - 使用 PHP 通过 SSL 将 AWS EC2 实例连接到 RDS MySQL

c# - 使用 Sendgrid 在 Azure 上发送简单的电子邮件

r - 带有 SSL 的 NGINX 上的 Shiny 服务器