使用 PHP mail() 函数通过 Exchange 发送电子邮件时出现延迟(使用 sendmail 作为中继)

发布于 2024-08-05 12:08:29 字数 357 浏览 4 评论 0原文

我使用 PHP mail() 函数从 Linux 服务器发送电子邮件,但使用 Exchange 作为主要 MTA。为了实现此目的,sendmail 已设置为将所有内容中继到本地 Exchange 服务器,然后由本地 Exchange 服务器发送电子邮件。

这工作正常,但 PHP 脚本似乎要等到超时限制才能完成。我想也许它正在等待来自 sendmail 的响应,但它没有响应,这只是一个中继?

我为“sendmail_path”-odb 指定了 php.ini 命令行选项,该选项应以“后台”传递模式启动 sendmail,这意味着在单独的进程中发送电子邮件,然后立即返回。但PHP脚本仍然需要30秒才能结束。

有人有什么想法吗?我有点难住了。 谢谢。

I'm using the PHP mail() function to send emails from a Linux server, but using Exchange as the main MTA. To achieve this sendmail has been set up to relay everything to the local Exchange server, which then sends the emails out.

This is working correctly, but the PHP script seems to wait until the timeout limit before finishing. I thought perhaps it's waiting for a response from sendmail, which doesn't come becomes it's just a relay?

I specified the php.ini command line option for "sendmail_path" -odb, which should start sendmail with the "background" delivery mode, meaning to fire off emails in a separate process and then immediately return. But it still takes 30 seconds for the PHP script to end.

Anyone have any ideas? I'm a bit stumped.
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

倾`听者〃 2024-08-12 12:08:29

间接解决方案。

我们所做的是使用 php 的 system() 在后台发送电子邮件,这样用户就不必等待电子邮件发出。

像这样的东西......

<?php //sendEmail.php
mail($argv[1], $argv[2], $argv[3]);
?>

你的脚本:

<?php
...
system("php sendEmail.php [email protected] 'subject' 'message' 1>/dev/null 2>&1 &");
...
?>

An indirect solution.

What we do is use php's system() to send emails in the background so the user doesnt have to wait for the email to go out.

something like this...

<?php //sendEmail.php
mail($argv[1], $argv[2], $argv[3]);
?>

your script:

<?php
...
system("php sendEmail.php [email protected] 'subject' 'message' 1>/dev/null 2>&1 &");
...
?>
浪漫人生路 2024-08-12 12:08:29

如果不查看 php/mail 日志就不能说太多。但为什么不直接从 PHP 发送到您选择的 MTA?只需使用像 PHPMailer 这样的库,身份验证就会很容易。

另外,出于调试目的,您可以安装 postfix(在带有包管理器的 Linux 上需要 3 秒)并将其设置为中继,Postfix 日志在详细模式下非常广泛,您可以发现 sendmail 是否是您的瓶颈。

Can't say much without looking at the php/mail logs. But why don't you send from PHP directly to your MTA of choice? just use a library like PHPMailer and the authentication will be easy.

Also for debugging purposes you could install postfix (on linux with a package manager takes 3 seconds) and set it up as relay, Postfix logs are pretty extensive on verbose mode and you could discover if sendmail was your bottleneck.

一身仙ぐ女味 2024-08-12 12:08:29

-odb 已弃用(sendmail 版本 8.7 及以上)。 1
考虑使用 -ODeliveryMode=b(用于 sendmail 命令行或 sendmail_path 设置)
或者在 PHP mail 函数的附加参数中添加 O DeliveryMode=b2

-odb was deprecated (sendmail version 8.7 onwards). 1
Consider using -ODeliveryMode=b (for the sendmail command line or sendmail_path setting)
Or add O DeliveryMode=b in the additional parameters of the PHP mail function. 2

只是我以为 2024-08-12 12:08:29

另一种方法可能是使用 PEAR 的 Mail。我用它来发送电子邮件到 qmail 和 Exchange SMTP 服务器。

An alternative might be to use PEAR's Mail. I have used it to send emails to qmail and Exchange SMTP servers.

好久不见√ 2024-08-12 12:08:29

我有一个类似的问题。就我而言,基础设施团队实际上人为添加了 30 秒的延迟。我认为这实际上更像是一个等待确认电子邮件已实际发送的设置,默认情况下等待 30 秒,而不是有人明确任意设置 30 秒的延迟。无论如何,听起来你们在同一条船上。与管理 Exchange 服务器的人员联系,告诉他们发生了什么,并看看他们是否可以发现该设置。就我而言,我必须实际记录 Wireshark 发生的情况,然后才能让团队相信实际上是 Exchange 而不是我的应用程序存在问题。

I had a similar question. In my case, the infrastructure team had actually added a 30 second artificial delay. I think it's actually more like a setting to wait for confirmation that the email has actually been sent that by default waits 30 seconds than someone explicitly setting a 30 second delay arbitrarily. Regardless, sounds like you're in the same boat. Check with whoever manages the Exchange server, tell them what's happening, and see if they can spot the setting. In my case, I had to actually log what was happening with Wireshark before I convinced the team that there was actually a problem with Exchange and not my application.

把梦留给海 2024-08-12 12:08:29

如果有任何帮助,我的 sendmail_path 如下所示:

sendmail_path = /usr/sbin/sendmail -t -i

If it's any help my sendmail_path looks like this:

sendmail_path = /usr/sbin/sendmail -t -i
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文