1

我正在尝试使用 PHPMailer_V5.1 通过 gmail 发送电子邮件。

收到以下错误,

SMTP -> 错误:无法连接到服务器:无法找到套接字传输“ssl” - 您在配置 PHP 时是否忘记启用它?(41961176) SMTP 错误:无法连接到 SMTP 主机。

以下是PHPMailer下载附带的代码,我只是修改了必填字段,

<?php
    require_once('../class.phpmailer.php');
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

    $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

    $mail->IsSMTP(); // telling the class to use SMTP

    try {
      $mail->Host       = "mail.yourdomain.com"; // SMTP server
      $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
      $mail->SMTPAuth   = true;                  // enable SMTP authentication
      $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
      $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
      $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
      $mail->Username   = "santosh1984naidu@gmail.com";  // GMAIL username
      $mail->Password   = "********";            // GMAIL password
      $mail->AddReplyTo('santosh1984naidu@gmail.com', 'First Last');
      $mail->AddAddress('santosh1984naidu@gmail.com', 'John Doe');
      $mail->SetFrom('santosh1984naidu@gmail.com', 'First Last');
      $mail->AddReplyTo('santosh1984naidu@gmail.com', 'First Last');
      $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
      $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
      $mail->MsgHTML(file_get_contents('contents.html'));
      $mail->AddAttachment('images/phpmailer.gif');      // attachment
      $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
      $mail->Send();
      echo "Message Sent OK</p>\n";
    } catch (phpmailerException $e) {
      echo $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
      echo $e->getMessage(); //Boring error messages from anything else!
    }
    ?>
4

2 回答 2

8

根据错误,似乎 PHP 中未启用 SSL。在我的脑海中,我相信你需要取消评论

扩展 = PHP_openssl.dll

在你的 php.ini 文件中

如果您的系统上已经设置了 SSL,以下内容应该可以帮助您安装 SSL:

http://us2.php.net/manual/en/openssl.installation.php

于 2010-01-20T02:53:36.220 回答
0

好吧,错误消息说明了一切:

找不到套接字传输“ssl” - 您在配置 PHP 时是否忘记启用它?

这意味着 PHP 版本没有配备必要的库来通过 SSL 与邮件服务器(或任何其他服务器)进行通信。

如果您没有对服务器的 root 访问权限,这可能是您的服务器管理员/提供商的问题。

论坛中的类似讨论中,一个听起来很现实的可能解决方案:

我的猜测是,要么没有为 apache 安装 mod_ssl,要么已经安装了 mod_ssl,但 mod_ssl 的配置行在 httpd.conf 中被注释掉了(就像我在 suse9 上一样)。如果 mod_ssl 启动并运行,apxs 将仅在 php 中启用 ssl 功能

所以检查 mod_ssl 是否可用 + 在 apache 中启用,然后尝试重新编译 php

./configure --with-apxs2=/usr/sbin/apxs --with-mysql --enable-ssl

于 2010-01-20T02:45:39.177 回答