【问题标题】:php mail function and mail serverphp邮件功能和邮件服务器
【发布时间】:2013-03-08 02:49:21
【问题描述】:

使用 php mail http://php.net/manual/en/function.mail.php 如果邮件发送成功,则返回 true。

但是对于我的网络主机,发送速率是 3000/小时,然后服务器将在达到 3000 限制后存储 450 封电子邮件(这是 3000 限制的 15%)。

我想确认的是,当 php 邮件函数返回 true 时,它​​是否可以处理这些设置。邮件服务器是否向邮件功能确认它发送正常,还是邮件功能对此“视而不见”?

邮件服务器是否对函数说,达到限制的电子邮件未发送所以返回 false?

【问题讨论】:

  • 不要使用 mail() 进行群发邮件,即使在邮件页面上也这样说。 **"值得注意的是mail()函数不适合循环处理大量邮件。该函数为每封邮件打开和关闭一个SMTP套接字,效率不高。**
  • 主机不太可能正在为您排队。更有可能是把他们赶出去。只有主人可以确认这一点。小心发送大量电子邮件,尤其是来自共享主机的电子邮件,尤其是在您不知道自己在做什么的情况下:-)
  • 邮件函数只有在被接受投递时才返回true,但它不知道之后会发生什么。就像文档状态一样,“重要的是要注意,仅仅因为邮件被接受交付,并不意味着邮件实际上会到达预期的目的地。”

标签: php email


【解决方案1】:

使用 PHP 自带的mail() 函数并不是最佳解决方案。使用 SWIFTMAILER http://swiftmailer.org/ 这将用作 SMTP 服务:

使用 swiftmailer 作为 SMTP 服务时的代码示例:

require_once 'lib/swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
  ->setUsername('your username')
  ->setPassword('your password')
  ;

/*
You could alternatively use a different transport such as Sendmail or Mail:

// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');

// Mail
$transport = Swift_MailTransport::newInstance();
*/

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
  ->setBody('Here is the message itself')
  ;

// Send the message
$result = $mailer->send($message);

【讨论】:

    猜你喜欢
    • 2011-08-19
    • 2018-11-11
    • 1970-01-01
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多