【问题标题】:PHP to send smtp emails with pear mail modulePHP 使用 pear 邮件模块发送 smtp 电子邮件
【发布时间】:2012-04-13 00:23:51
【问题描述】:

最初我通过 mail() 函数发送电子邮件,但它们总是被夹在垃圾邮件文件夹中,所以现在我想使用 PHP PEAR 使用 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"] = "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

谁能给点建议。

【问题讨论】:

  • 你的代码有require语句吗?我原以为错误会由一个人产生,但这可能是因为我对 PEAR 缺乏了解。我听说 Swift Mailer 更好,这是我以前用过的。
  • 是的,它确实需要 Mail.php,我已经放弃了这个大声笑,我正在使用普通的 mail() 函数。

标签: pear php


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2012-05-29
    • 2016-04-17
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多