【问题标题】:How to send mail in PHP by using ubuntu operating system?如何使用 ubuntu 操作系统在 PHP 中发送邮件?
【发布时间】:2012-04-03 20:08:42
【问题描述】:

这是我的代码,我在我的项目文件夹中包含了所有文件,例如 mime.phpmail.php and Mail.php,但邮件功能仍然无法正常工作。

<?php
require "Mail.php";
require_once 'Mail/mime.php';
require_once 'Mail/mail.php';

$to = "mymail@gmail.com";
$from = "sendmail@gmail.com";
$subject = utf8_decode("mail");
$message = utf8_decode("hi");
$attachment_data = utf8_decode("testingmail1-filecontent");
$attachment_filename = utf8_decode("testingmail1.php");
send_mail_utf8_with_attachment($to, $from, $subject, $message ,$attachment_data, $attachment_filename);

function send_mail_utf8_with_attachment($to, $from, $subject, $message = "",$attachment_data="", $attachment_filename="")
{
    $params = array();
    $params['head_charset'] = 'utf-8';
    $params['text_charset'] = 'utf-8';
    $params['html_charset'] = 'utf-8';
    $params['eol'] = "\n";
    $hdrs = array('From'    => $from ,'Subject' => $subject );
    $mime = new Mail_mime($params);
    $mime->setTXTBody($message);

    if (strlen($attachment_data) && strlen($attachment_filename))
    {
        $mimeType = "application/octet-stream";
        $mime->addAttachment($attachment_data, $mimeType, $attachment_filename, false);
    }

    $body = $mime->get();
    $hdrs = $mime->headers($hdrs);
    $mail =& Mail::factory('mail');
    return $mail->send($to, $hdrs, $body);
} 
?>

我已经实现了所有安装:

sudo apt-get install php-pear
sudo pear install mail
sudo pear install Net_SMTP
sudo pear install Auth_SASL
sudo pear install mail_mime

但还是不行。

【问题讨论】:

  • sendmail@gmail@gmail.com 错误。
  • 您遇到什么错误?您是否在 php.ini 中设置了邮件发送服务器/详细信息?
  • 这在 Windows 中运行良好,但在 Ubuntu 中却没有。我安装了所有梨包,但仍然没有结果

标签: php email pear


【解决方案1】:

您必须在 Ubuntu 上配置 SMTP 服务器。我个人通常使用 ssmtp & gmail 看看那里的相关教程:http://blog.seeit.org/2010/08/php-mail-with-ubuntu-desktop-and-gmail/

【讨论】:

    【解决方案2】:

    可能您的 php.ini 发送邮件设置不正确。试试mail('caffeinated@example.com', 'My Subject', $message); 之类的东西。如果这是有效的,那么您在 php.ini 中的邮件设置是正确的。

    【讨论】:

    • 我也做了,但还是不行。我认为这可能是某些文件中的配置有问题。如何更改 php.ini 文件中的设置?
    • 你能从shell发送邮件吗? mail your@email.de + 主题 + CTRL+D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多