PHP发送smtp电子邮件与梨邮件模块

PHP发送smtp电子邮件与梨邮件模块

问题描述:

最初我通过邮件()函数发送电子邮件,但他们总是陷入垃圾邮件文件夹,所以现在我想发送他们使用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

如果您想尝试修复当前库,那么您的托管服务提供商可能会遇到问题,因为他们只知道他们的存储系统结构。

您的另一种选择可能是使用Swift Mailer您可以上传该库,然后将其包含在您要使用的每个页面中。该网站有良好的文档和经验斯威夫特梅勒可以做你想做的SMTP。

+0

谢谢,虐待这个未来的想法 – 2012-04-13 11:24:03