在 Linux 上对 SMTP 服务器使用默认的 PHP 邮件功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11942896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:30:24  来源:igfitidea点击:

Use default PHP mail function with SMTP server on Linux

phpemailsmtpsendmail

提问by Boardy

I am working on a php/c# project which is an Email Server with a web interface to manage the Email Server application.

我正在开发一个 php/c# 项目,它是一个带有 Web 界面的电子邮件服务器,用于管理电子邮件服务器应用程序。

The program is supposed to work on windows and linux but I have been mostly doing my development in windows.

该程序应该在 windows 和 linux 上运行,但我主要在 windows 上进行开发。

I've not come onto testing in Linux and have found a horrible problem.

我还没有在 Linux 中进行测试,并发现了一个可怕的问题。

From what I have googled on Windows PHP you can choose an SMTP server that you want to use, but it looks as if on Linux you don't have this option so when PHP sends an email it completely bypasses my program.

根据我在 Windows PHP 上搜索的内容,您可以选择要使用的 SMTP 服务器,但看起来在 Linux 上您没有此选项,因此当 PHP 发送电子邮件时,它完全绕过了我的程序。

Is there a way to make PHP use an SMTP server of your choice, I know you can use PEAR to overrride the SMTP settings but I'd prefer that the standard PHP mail function would work so other software like PHPBB forum would send emails via my SMTP server instead of the default php mail.

有没有办法让 PHP 使用您选择的 SMTP 服务器,我知道您可以使用 PEAR 来覆盖 SMTP 设置,但我更喜欢标准的 PHP 邮件功能可以工作,因此其他软件(如 PHPBB 论坛)可以通过我的SMTP 服务器而不是默认的 php 邮件。

Is this something that is possible or is my only option to use pear?

这是可能的还是我使用梨的唯一选择?

采纳答案by Mike Brant

You standard php mail function will just send to whatever is defined as the sendmail _path in php.ini

您标准的 php 邮件函数将只发送到 php.ini 中定义为 sendmail _path 的任何内容

This is typically sendmail -t -i

这通常是 sendmail -t -i

You would need to configure sendmail to use smtp.

您需要将 sendmail 配置为使用 smtp。

FWIW, most developer who do a lot of mail sending from PHP apps revile the mail() and instead use one of many mailing libraries (or services) which provide better configurability/reliability.

FWIW,大多数从 PHP 应用程序发送大量邮件的开发人员都谴责 mail(),而是使用提供更好的可配置性/可靠性的众多邮件库(或服务)之一。

You could for example pipe the mail function to your own PHP script and use whatever library you wanted to in that script in order to do mail sending (and thus preserving the use of mail() function across applications).

例如,您可以将邮件函数通过管道传输到您自己的 PHP 脚本,并使用您想要在该脚本中使用的任何库来发送邮件(从而保留跨应用程序使用 mail() 函数)。

回答by drew010

It's not possible to have the mail()function use an SMTP server on non-Windows systems.

mail()在非 Windows 系统上不可能让该功能使用 SMTP 服务器。

See the docs on the php.inisetting smtp.

请参阅有关php.ini设置smtp的文档。

phpmailerhas become a widely used PHP library for sending email. It supports a variety of options including SMTP and various authentication types and SSL/TLS. I'd recommend using that (or something similar See also Zend_Mail) if you need to send messages using SMTP.

phpmailer已成为一个广泛使用的用于发送电子邮件的 PHP 库。它支持多种选项,包括 SMTP 和各种身份验证类型以及 SSL/TLS。如果您需要使用 SMTP 发送消息,我建议使用它(或类似的东西另见Zend_Mail)。

So you won't be able to use the mail function, but your only other option isn't Pear.

因此,您将无法使用邮件功能,但您唯一的其他选择不是 Pear。