2010-01-20 182 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

相關問題