PHP 使用梨邮件模块发送 smtp 电子邮件


PHP to send smtp emails with pear mail module

>最初我通过mail()函数发送电子邮件,但它们总是被垃圾邮件文件夹捕获,所以现在我想使用PHP PEAR使用SMTP发送它们,但是我遇到了一些错误。

在功能中.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"] = "xxx@auto-sal.es"; 
    $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());}

但是我收到以下错误;

致命错误:在 中找不到类"邮件" /mounted-storage/hoxxx/xxx01/xx/auto-sal.es/functions.php 在第 17 行

但是,我的主机确实安装了这些模块 https://www.servage.net/wiki/List_of_PEAR_modules

任何人都可以指教。

如果您想尝试修复当前库,那么对于您的托管服务提供商来说可能是一个问题,因为只有他们知道其存储系统的结构。

您的另一种选择可能是使用 Swift Mailer,您可以上传库,然后将其包含在您要使用的每个页面中。该网站有很好的文档,根据经验,Swift Mailer可以做你想做的SMTPT。