Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclamation Point Randomly In Result of PHP HTML-Email

Tags:

html

php

email

I'm getting exclamation points in random spots in the result of this PHP email function. I read that it's because my lines are too long or I have to encode the email in Base64 but I do not know how to do that.

This is what I have:

$to = "[email protected]";
$subject = "Pulling Hair Out";
$from = "[email protected]";
$headers = "From:" . $from;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 64bit\r\n";

mail($to,$subject,$message,$headers); 

How do I fix this so there's no random ! in the result? Thanks!

like image 622
Tom Avatar asked Aug 23 '13 17:08

Tom


People also ask

Why does my email have an exclamation mark?

The exclamation mark indicates that this is a new contact that has been entered, but hasn't been verified as a legitimate contact that you want to keep in the database.

What does exclamation mean in PHP?

It's called the negation unary operator. It flips the Boolean value (coercing to Boolean if need be) of a value. For example... ! 0; // True !

What does (!) Mean in email?

Let's start with the definition of the exclamation point (!) from about.com: A punctuation mark (!) used after a sentence that expresses a strong emotion.

What does an exclamation point mean in HTML?

Markup Declaration Open: "<!", when followed by a letter or "--" or "[", signals one of several SGML markup declarations. The only purpose it serves in HTML is to introduce comments.


2 Answers

Try to use this piece of code:

$to = "[email protected]";
$subject = "Pulling Hair Out";
$from = "[email protected]";
$headers = "From:" . $from;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 64bit\r\n";

$finalMessage = wordwrap( $message, 75, "\n" );

mail($to,$subject,$finalMessage,$headers);

The problem is that one line should not be longer than 998 characters. (see also https://stackoverflow.com/a/12840338/2136148)

like image 81
knobli Avatar answered Oct 19 '22 09:10

knobli


As stated here: Exclamation Point in HTML Email

The issue is that your string is too long. Feed an HTML string longer than 78 characters to the mail function, and you will end up with a ! (bang) in your string.

This is due to line length limits in RFC2822 https://www.rfc-editor.org/rfc/rfc2822#section-2.1.1

like image 21
Lumberjack Avatar answered Oct 19 '22 09:10

Lumberjack