邮件不使用SMTP通过SSL发送PHPMailer

Jam*_*ing 6 php email ssl smtp phpmailer

我试图使用PHPMailer通过SMTP发送电子邮件,但到目前为止没有运气.我已经阅读了许多SO问题,PHPMailer教程和论坛帖子,但仍然无法使其工作.我将记录尽可能多的失败尝试,因为我记得要节省时间,但首先是我使用的代码:

<?php
    session_start();
    error_reporting(E_ALL);
    ini_set('display_errors','On');

    require('includes/class.phpmailer.php');
    include('includes/class.smtp.php');
    $mail = new PHPMailer(); 

    $name = $_POST["name"];
    $guests = $_POST["guests"];
    $time = $_POST["time"];

    $message = "<h1>".$name." has booked a table for ".$guests." at ".$time."</h1>";

    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host       = "ssl://smtp.gmail.com"; // SMTP server
    $mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->Port       = 26;                    // set the SMTP port for the GMAIL server
    $mail->Username   = "myEmail@gmail.com"; // SMTP account username
    $mail->Password   = "myPassword";        // SMTP account password
    $mail->SetFrom('myEmail@gmail.com', 'James Cushing');
    $mail->AddReplyTo("myEmail@gmail.com","James Cushing");
    $mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";
    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";
    $mail->MsgHTML($message)
    $address = "myOtherEmail@me.com";
    $mail->AddAddress($address, "James Cushing");

    if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    }
?>
Run Code Online (Sandbox Code Playgroud)

首先,当我运行此代码时,我得到两个不同的错误.在我的本地服务器上,我收到错误:
SMTP - >错误:无法连接到服务器:操作超时(60)
以下发件人地址失败:myEmail@gmail.com:调用Mail()而未连接
Mailer错误:以下来自地址失败:myEmail@gmail.com:调用Mail()而未连接

我在网络服务器上运行相同代码时遇到同样的错误,但第一行是:
SMTP - >错误:无法连接到服务器:网络无法访问(101)

显然值得指出的是,我没有使用文字"myEmail@gmail.com",但我已经用自己的电子邮件替换了这篇文章.

我尝试过的事情
- 使用iCloud SMTP服务器
- 使用不同的端口
- 在我的php.ini文件中启用OpenSSL扩展
- 从各种PHPMailer示例复制代码
- 使用Google的"DisplayUnlockCaptcha"系统启用连接
- 发送到不同的端口地址 - 从Username属性中删除"@ gmail.com" - 其他一些我不记得的事情

这已经让我疯了大约一天,所以如果有人能解决它,他们将成为英雄.

谢谢

ybe*_*ert 32

$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = "myemail@gmail.com";
$mail->Password = "**********";
$mail->Port = "465";
Run Code Online (Sandbox Code Playgroud)

这是一个有效的配置.

尝试替换你拥有的东西