Home > Web Development > Wierd Exclamation characters in the html email

Wierd Exclamation characters in the html email

In case you are trying to send an html email via the mail function in PHP and you are getting weird formatting and exclamation characters, then you need to insert line breaks (“\n”) into the message of your email

Check out the php documentation @ http://php.net/manual/en/function.mail.php
It says: Each line should be separated with a LF (\n). Lines should not be larger than 70 characters.

So if you are getting badly formatted email, one of the reasons is because of this.

Just before you send your email, you can do this

$email_message = "blah blah blah ..... a long email message.....";
$email_message =  wordwrap($email_message, 70, "\n");
mail($to, $subject, $email_message, $headers);  //send email
Categories: Web Development
  1. pungi
    April 26, 2011 at 8:37 AM

    thanks this helped.

    I just added line below to ensure this.
    $HtmlReport =~ s/(.{0,200}\S+)\s+/$1\n/g;

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: