Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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包含吗?_Php_Email - Fatal编程技术网

我可以在电子邮件标题中使用php包含吗?

我可以在电子邮件标题中使用php包含吗?,php,email,Php,Email,试图做到这一点 $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: $sales_rep_name <$sales_rep>' . "\r\n"; mail($to,$subject,$message,$headers); 但它不起作用。有什么想法吗?需要双引号才能在字符串中插入

试图做到这一点

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: $sales_rep_name <$sales_rep>' . "\r\n";
mail($to,$subject,$message,$headers);

但它不起作用。有什么想法吗?

需要双引号才能在字符串中插入变量:

$headers .= "From: $sales_rep_name <$sales_rep>" . "\r\n";
            ^                                  ^
$headers.=“发件人:$sales\u rep\u name”。“\r\n”;
^                                  ^
字符串“not working”不是PHP中的内置错误消息。“not working”是一个无用的诊断。我们的回答也可以是“好吧,也许你支付的字符串不够”。OP:请参阅进一步解释(其他人也一样)。
$headers .= "From: $sales_rep_name <$sales_rep>" . "\r\n";
            ^                                  ^