Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在sendmail中设置“发件人”字段?_Php_Linux_Unix_Ubuntu_Sendmail - Fatal编程技术网

Php 如何在sendmail中设置“发件人”字段?

Php 如何在sendmail中设置“发件人”字段?,php,linux,unix,ubuntu,sendmail,Php,Linux,Unix,Ubuntu,Sendmail,我得到了简单的代码片段 mail('to'=?UTF-8?B?')。base64_编码('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" 127.0.0.1 localhost.localdomain lo

我得到了简单的代码片段

mail('to'=?UTF-8?B?')。base64_编码('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"
127.0.0.1       localhost.localdomain localhost pm
我的
/etc/hosts

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

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

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

在PHP的INI文件中,包含非字母数字字符的字符串值必须用双引号(
)。
中描述了这一点,但它似乎也适用于PHP的内部(配置)INI解析

因此,您的INI行应该是:

sendmail_path = "/usr/sbin/sendmail -t -i -F Test -f example@mysite.test"
您可以选择引用sendmail参数的值(注意转义序列):

现在,
sendmail
将从以下内容生成此

From: "Test" <example@mysite.test>
From:“测试”

为什么不使用
php.ini中的
sendmail\u选项?@Barmar它被标记为仅适用于Win32的
。但无论如何,我在写这篇文章之前已经试过了。你试过将整个选项值用引号括起来吗?例如,
“/usr/sbin/sendmail-t-I-F Test-Fexample@mysite.test“
通常使用引号来分隔字符串。至少应该引用带空格的字符串。@Lukas
-f
现在显示在电子邮件中,
-f
被忽略。我的路径:“/usr/sbin/sendmail-t-i-FTest”-fexample@mysite.test"