2010-01-20 183 views
1

我想通过使用PHPMailer_V5.1的Gmail发送电子邮件。无法使用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 = "[email protected]"; // GMAIL username 
     $mail->Password = "********";   // GMAIL password 
     $mail->AddReplyTo('[email protected]', 'First Last'); 
     $mail->AddAddress('[email protected]', 'John Doe'); 
     $mail->SetFrom('[email protected]', 'First Last'); 
     $mail->AddReplyTo('[email protected]', '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! 
    } 
    ?> 
+0

你似乎在顶部被设置主机mail.yourdomain.com。尝试删除它,看看它是否有帮助。 – 2010-01-20 02:47:00

+0

不删除它没有任何区别 – San 2010-01-20 02:55:05

回答

8

基于错误似乎SSL不支持PHP。关闭我的头顶,我相信,你必须解除

延长= PHP_openssl.dll

在php.ini文件

以下应该可以帮助您安装SSL,如果它已经在系统上安装:

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

+0

哇..uncommenting扩展= PHP_openssl.dll工作。 我不明白为什么它评论。 这是我第一天的php编码,我有很多要学的 – San 2010-01-20 02:59:45

+2

某些功能的默认评论。如果你看看php.ini,你会发现其中的几个。这个原因我不确定。我很高兴你让它工作。 – 2010-01-20 03:11:06

+0

+1良好的通话Waleed。 – 2010-01-20 03:14:33

0

那么,错误消息说,这一切:

Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?

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

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

similar discussion in a forum,一个可能的解决方案听起来很实际:

My guess is that either mod_ssl is not installed for apache or it is installed but the configuration lines for mod_ssl are commented out in httpd.conf (like it was on suse9 for me). apxs will only enable ssl functions in php if mod_ssl is up and running

So check mod_ssl is available + enabled in apache then try recompiling php with

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

+0

我取消了“LoadModule ssl_module modules/mod_ssl.so”,并重新启动但没有改变,我仍然收到错误。 如何检查mod_ssl是否可用? – San 2010-01-20 02:52:38

+0

我想你也必须用'--enable-ssl'重新编译PHP。查看'phoinfo();'看看PHP是如何编译的。 – 2010-01-20 02:59:29

+0

@San:您还需要在php中启用支持,我认为Waleed提到了上游。注意他给了windows特定的指令,指向扩展名,它应该是* nix框中的'.so'。 – prodigitalson 2010-01-20 03:01:35

相关问题