2011-06-20 81 views
14

如何包含使用PHP Pear Mail的mail.php。我使用下面的代碼test.php的文件:如何使用php pear郵件

require_once "Mail.php"; 

    $from = "<[email protected]>"; 
    $to = "<[email protected]>"; 
    $subject = "Hi!"; 
    $body = "Hi,\n\nHow are you?"; 

    $host = "ssl://smtp.gmail.com"; 
    $port = "465"; 
    $username = "<[email protected]>"; 
    $password = "testtest"; 

    $headers = array ('From' => $from, 
     'To' => $to, 
     'Subject' => $subject); 
    $smtp = Mail::factory('smtp', 
     array ('host' => $host, 
     'port' => $port, 
     'auth' => true, 
     'username' => $username, 
     'password' => $password)); 

    $mail = $smtp->send($to, $headers, $body); 

    if (PEAR::isError($mail)) { 
     echo("<p>" . $mail->getMessage() . "</p>"); 
    } else { 
     echo("<p>Message successfully sent!</p>"); 
    } 

,並遇到了以下錯誤通過這個代碼:

Warning: require_once(Mail.php) [function.require-once]: failed to open stream: No such file or directory in D:\Hosting\6525150\html\test.php on line 3 

    Fatal error: require_once() [function.require]: Failed opening required 'Mail.php' (include_path='.;C:\php5\pear') in D:\Hosting\6525150\html\test.php on line 3 

誰能告訴我是什麼問題?

回答

12

檢查梨是否安裝在系統中。如果是,那麼在php.ini include_path指令

指定路徑梨的安裝目錄,您需要安裝PEAR和PEAR郵件包裹得到它的工作

+0

pear安裝在我的服務器上。並且包含路徑爲「C:\ php5 \ pear」 – Deepa

+1

您還需要安裝Mail軟件包 –

+1

還使用phpinfo()檢查php include_path; –

20

你的錯誤信息是不言自明。確保你的機器上安裝了PEAR :: Mail,如果沒有,請安裝它。

的Linux:

梨安裝Mail

的Windows:

http://www.geeksengine.com/article/install-pear-on-windows.html

如果該進程完成。

然後請註明您Mail.php在腳本(實例化對象Mail以前可能這也許應該踢你的警告遠

包括「/path/to/pear/Mail.php」。

通過set_include_path( 「/路徑/到/梨」); 包括 「Mail.php」;

也請確保there is enough permissionMail.php給出供PHP閱讀。

+1

不足以做'包含'Mail.php';'? –

+1

@FranciscoCorrales - 是的,只要你在你的PEAR目錄中安裝了郵件包。 –

0

我拼湊從網上這些步驟,它的工作原理:

如何安裝PEAR: 1. Download go-pear.phar at http://pear.php.net/go-pear.phar & save to php directory (eg C:\Program Files\PHP\) 2. Open a command window as administrator, move to your php directory, CMD: php go-pear.phar 3. Accept the default value for everything it asks about; system wide, path options, updating your php.ini etc 4. In php directory double-click PEAR_ENV.reg to update your registry 然後,你需要安裝PEAR MAIL: 5. CMD: php go-pear.phar 6. CMD: pear install --alldeps mail 7. CMD: pear channel-update pear.php.net 確保有這個在你的電子郵件的腳本:require_once 「Mail.php」;