gpt4 book ai didi

php - 如何设置sendmail中的From字段?

转载 作者:太空宇宙 更新时间:2023-11-04 04:05:06 25 4
gpt4 key购买 nike

我有简单的代码片段

mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, 'Content-Type: text/html; charset=UTF-8;');

我的服务器在 Ubuntu 上。所以 php.ini

sendmail_path = /usr/sbin/sendmail -t -i -F "Test" -f "example@mysite.test"

我的/etc/hosts

127.0.0.1       localhost.localdomain localhost pm

我收到来自 www-data@localhost.localdomain 的电子邮件。我不想在调用 mail 时显式设置 From: header 。我做错了什么?

最佳答案

为了正确的顺序,我再次写下我的评论作为常规答案。

在 PHP 的 INI 文件中,包含非字母数字字符的字符串值必须用双引号 (") 引起。
parse_ini_file() documentation 中对此进行了描述。 ,尽管它似乎也适用于 PHP 的内部(配置)INI 解析。

因此,您的 INI 行应该是:

sendmail_path = "/usr/sbin/sendmail -t -i -F Test -f example@mysite.test"

您可以选择引用 sendmail 参数的值(注意转义序列):

sendmail_path = "/usr/sbin/sendmail -t -i -F \"Test\" -f \"example@mysite.test\""

现在,sendmail 将生成此 From: header :

From: "Test" <example@mysite.test>

关于php - 如何设置sendmail中的From字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21519115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com