Gmail removes link tags, how to avoid it

I am trying to send with the mail () function; rich text containing links; I am sending this code ...

Please, access <a href="http://www.site.md/contact/en/"> Contact </a> to send all these information 

throw firebug I see that the link tags are removed, the code becomes like

  Please, access <a>Contact</a> to send all these information 

I need this script, after I forbade the person who violated the rules to send an email to tell the reason why we forbade it. In another email service, email arrives without problems, what is my mistake, sorry for my English, I will show part of the script for sending email, important ...

  // Set and wordwrap message body $body = "From: $name\n\n"; $body .= "Message: $message"; $body = wordwrap($body, 70); // Build header $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: $email\n"; if ($cc == 1) { $headers .= "Cc: $email\n"; } $headers .= "X-Mailer: PHP/Contact"; // Send email if( !@mail ($to, $subject, $body, $headers)) { echo '<b> ERROR ! </b> Unfortunately, a server issue prevented delivery of your message<br />'; } 
+6
html php email gmail
source share
4 answers

If you are not doing something in $ body in code that you did not post here, I assume the reason for this is wordwrap (). The php manual uses a function that can help the user: http://www.php.net/manual/en/function.wordwrap.php#89782

+2
source share

It may be late, but well, just figure it out. At least what I see here. Basically, I generate a dynamic newsletter based on some data, and when I found the specific syntax inside the line, I had to replace it with the anchor tag. Anyway, here it is:

Bad formatting:

 "<a href='" + url + "'>" + name + "</a>"; 

Good formatting:

 '<a href="' + url + '">' + name + '</a>'; 

Direct answer, use double quotes for the href attribute.

0
source share

Part of the problem is long lines, but wordwrap() not enough to solve this problem.

The email may contain arbitrarily long lines, but they are transmitted using a protocol that allows only short lines. Thus, long lines should be split. Protocol lines are tags that have been separated by appending = to complete them, so that starts with what looks like this.

 Characters 2 3 4 5 6 7 12346790123456789012345678901234567890132456789012345678901234567890123456789 This is a long line with text which goes beyond the 78 character limit imposed by the protocol 

ends this way

 This is a long line with text which goes beyond the 78 character limit= imposed by the protocol 

Using = is similar, although it means that = cannot be used in your message, so it needs to be escaped. So you need to replace = in your message with = 3D (where 3D is the hex code for =).

It is also advisable to replace any control characters (with ascii <32) with = xx and with ascii over 126. I use these functions to do this, you just need to do $message=encodeText($message) before sending, and the problem should disappear.

 function encodeText($input) { // split input into lines, split by \r\n, \r or \n $lines=preg_split("/(?:\r\n|\r|\n)/", $input); $text=""; // for each line, encode it into a 78 char max line. for ($i=0; $i<count($lines); $i++) { $text.=encodeLine($lines[$i]); } return $text; } /** * This splits a line into a number of pieces, each shorter than the 78 char * limit. It also add continuation marks (ie =) to then end of each piece * of the resulting line, and escapes any = characters, control characters * or characters with bit 8 set, and backspace. * @return a multiline string (with /r/n linebreaks) */ function encodeLine($line) { $split=Array(); $result=""; $piece=''; $j=0; for ($i=0; $i<strlen($line); $i++) { // if you've just split a line, you'll need to add an = to the // end of the previous one if ($j>0 && $piece=="") $split[$j-1].="="; // replace = and not printable ascii characters with =XX if (ord($line{$i})==0x3D) { $piece.="=3D"; } else if (ord($line{$i})<32) { $piece.="=".bin2hex($line{$i}); } else if (ord($line{$i})>126) { $piece.="=".bin2hex($line{$i}); } else { $piece.=$line{$i}; } // if the resulting line is longer than 71 characters split the line if (strlen($piece)>=72) { $split[$j]=$piece; $piece=""; $j++; } } // the last piece being assembled should be added to the array of pieces if (strlen($piece)>0) $split[]=$piece; // if a piece ends in whitespace then replace that whitespace with =20 // for a space or =09 for a tab. for ($i=0; $i<count($split); $i++) { $last=substr($split[$i],-1); if ($last=="\t") $last="=09"; if ($last==" ") $last="=20"; $split[$i]=substr($split[$i],0,strlen($split[$i])-1).$last; } // assemble pieces into a single multiline string. for ($i=0; $i<count($split); $i++) { $result.=$split[$i]."\r\n"; } return $result; } 
0
source share

Try this, use stripslashes() with the email body, and it should work fine.

 $body= stripslashes($mail_message); 
0
source share

All Articles