dsiv4041
2015-08-25 00:55
浏览 53
已采纳

PHP mail()标头

I have the following headers that I want to pass to the mail() function:

$headers = "MIME-Version: 1.0
";
$headers .= "X-Mailer: PHP/" . phpversion()."
";
$headers .= "From:".$sender_email."
";
$headers .= "Subject:".$subject."
";
$headers .= "Reply-To: ".$sender_email."" . "
";
$headers .= "Content-Type: multipart/mixed; boundary=".md5('boundary1')."

";

$headers .= "--".md5('boundary1')."
";
$headers .= "Content-Type: multipart/alternative;  boundary=".md5('boundary2')."

";

$headers .= "--".md5('boundary2')."
";
$headers .= "Content-Type: text/plain; charset=ISO-8859-1

";
$headers .= $message."

";

$headers .= "--".md5('boundary2')."--
";
$headers .= "--".md5('boundary1')."
";
$headers .= "Content-Type:  ".$file_type."; ";
$headers .= "name=\"".$file_name."\"
";
$headers .= "Content-Transfer-Encoding:base64
";
$headers .= "Content-Disposition:attachment; ";
$headers .= "filename=\"".$file_name."\"
";
$headers .= "X-Attachment-Id:".rand(1000,9000)."

";
$headers .= $encoded_content."
";
$headers .= "--".md5('boundary1')."--"; 

$sentMail = @mail($recipient_email, $subject, $message, $headers);

Since I don't require the user to provide an e-mail address, can i exclude the "From" and Reply-To" fields and let the server auto-complete those values or would this action result in a malformed headers?

图片转代码服务由CSDN问答提供 功能建议

我有以下标题要传递给 mail()函数:

  $ headers =“MIME-Version:1.0 
 
”; 
 $ headers。=“X-Mailer:PHP /”。  phpversion()。“
 
”; 
 $ headers。=“From:”。$ sender_email。“
 
”; 
 $ headers。=“主题:”。$ subject。“
 \  n“; 
 $ headers。=”回复:“。$ sender_email。”“。  “
 
”; 
 $ headers。=“Content-Type:multipart / mixed; boundary =”。md5('boundary1')。“
 
 
 
”; 
 
 $ header  。=“ - ”。md5('boundary1')。“
 
”; 
 $ headers。=“Content-Type:multipart / alternative; boundary =”。md5('boundary2')。“
 
  
 
 
“; 
 
 $ headers。=” - “。md5('boundary2')。”
 
“; 
 $ headers。=”Content-Type:text / plain;  charset = ISO-8859-1 
 
 
 
“; 
 $ headers。= $ message。”
 
 
 
“; 
 
 $ headers。=” - “。  md5('boundary2')。“ -  
 
”; 
 $ headers。=“ - ”。md5('boundary1')。“
 
”; 
 $ headers。=“Content- 键入:“。$ file_type。”;“; 
 $ headers。=”name = \“”。$ file_name。“\”
 
“; 
 $ headers。=”Content-Transfer-Encoding:base64  
 
“; 
 $ headers。=”Content-Disposition:attachment;“; 
 $ headers。=”filename = \“”。$ file_name。“\”
 
“; 
 $ headers  。=“X-Attachment-Id:”。rand(1000,9000)。“
 
 
 
”; 
 $ headers。= $ encoded_content。“
 
”; 
 $ headers。  =“ - ”。md5('boundary1')。“ - ”;  
 
 $ sentMail = @mail($ recipient_email,$ subject,$ message,$ headers); 
   
 
 

由于我不要求用户提供 一个电子邮件地址,我可以排除“发件人”和“回复”字段,让服务器自动完成这些值,或者此操作会导致格式错误的标题吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题