[英]php fread() strips mail newlines
If I fopen/fread a text file, then send the content in an email, the newlines in the text file do not appear in the email when it arrives. 如果我打开/读取文本文件,然后通过电子邮件发送内容,则到达时文本文件中的换行符不会出现在电子邮件中。
For example, the text... 例如,文字...
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Sed leo erat,
rutrum posuere justo.
... arrives in the email inbox as: ...以以下方式到达电子邮件收件箱:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed leo erat, rutrum posuere justo.
I'm using this PHP code: 我正在使用以下PHP代码:
$fh = fopen($email_file,'r');
$message = fread($fh,filesize($email_file));
fclose($fh);
mail("email@example.com",$subject,$message,$headers);
//Assume each variable is declared and defined.
What am I missing? 我想念什么?
Edit: I needed to change the header Content-Type from HTML for the text version. 编辑:我需要从文本版本的HTML更改标题Content-Type。 Thanks to Yzmir and Footie.
感谢Yzmir和Footie。 Their questions / comments led me to the correct answer.
他们的问题/评论使我找到了正确的答案。
Try replacing the new lines with <br/>
and let me know if this solves it. 尝试用
<br/>
替换新行,让我知道是否可以解决。 If you can't do it for your files, do it in your code using: 如果无法对文件执行此操作,请使用以下代码在代码中进行操作:
$message = nl2br($message);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.