lhrec_106
lhrec_106

Reputation: 630

Why does the PHP add extra space in the email body for mail()?

Recently I use the mail($to, $subject, $content, $headers) to send email with a very long content including some images link like http://foo.com/image/1.jpg. The problem is that the email body sometimes break at some point and show the link like http://foo.com/image/1.jp+g, which will break the link. Or sometimes it just break the html tags like break <div> in to < div>, and finally the tag is shown in somewhere that is not supposed to be. Making the email looks so wired.

This problem has bugged me for a whole morning.

Upvotes: 1

Views: 1079

Answers (1)

lhrec_106
lhrec_106

Reputation: 630

Actually, I tracked down this problem and find that the body is too long that in the email, it will add newline automatically in the $content when applied in the mail() message body. As a result the image link will be likehttp://foo.com/image/1.jp g and the tags will be like < div>

This problem has troubled me for a whole morning. Now I found the solution would be adding \n at some point in your message so that your mail body is not only on one line, and the mail() will not add its own new line at the point that you do not want it to. Hope this can help someone if they have the similar problem.

Upvotes: 4

Related Questions