2012-04-13 151 views
0

最初我通過郵件()函數發送電子郵件,但他們總是陷入垃圾郵件文件夾,所以現在我想發送他們使用SMTP使用SMTP PEAR,但我越來越一些錯誤。PHP發送smtp電子郵件與梨郵件模塊

在functions.php我有電子郵件功能;

function send_mail($from,$to,$subject,$body) 
{ 
    // Setting up the SMTP setting 
    $smtp_info["host"] = "smtp1.servage.net"; 
    $smtp_info["port"] = "25"; 
    $smtp_info["auth"] = true; 
    $smtp_info["username"] = "[email protected]"; 
    $smtp_info["password"] = "xxx"; 

    // Creating the PEAR mail object : 
    $mail_obj =& Mail::factory("smtp", $smtp_info); 

    $headers = ''; 
    $headers .= "From: $from\n"; 
    $headers .= "Reply-to: $from\n"; 
    $headers .= "Return-Path: $from\n"; 
    $headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n"; 
    $headers .= "MIME-Version: 1.0\n"; 
    $headers .= "Date: " . date('r', time()) . "\n"; 

    $mail_sent = $mail_obj->send($to,$subject,$body,$headers); 

    if (PEAR::isError($mail_sent)) { print($mail_sent->getMessage());} 

但我得到以下錯誤;

Fatal error: Class 'Mail' not found in /mounted-storage/hoxxx/xxx01/xx/auto-sal.es/functions.php on line 17

然而,我的主人確實有這些模塊安裝https://www.servage.net/wiki/List_of_PEAR_modules

任何人都可以,請告知。

+0

你的代碼是否有require語句?我原以爲這個錯誤是由一個人產生的,但這可能是因爲我對PEAR缺乏瞭解。我聽說Swift Mailer更好,這是我以前用過的。 – Joel 2012-04-13 03:37:09

+0

是的它確實需要Mail.php,我已經放棄了這個哈哈,我使用正常的郵件()函數。 – 2012-04-13 10:01:08

回答

1

如果您想嘗試修復當前庫,那麼您的託管服務提供商可能會遇到問題,因爲他們只知道他們的存儲系統結構。

您的另一種選擇可能是使用Swift Mailer您可以上傳該庫,然後將其包含在您要使用的每個頁面中。該網站有良好的文檔和經驗斯威夫特梅勒可以做你想做的SMTP。

+0

謝謝,虐待這個未來的想法 – 2012-04-13 11:24:03