Gmail удаляет теги ссылок, как этого избежать

Я пытаюсь отправить с функцией mail (); богатый текст, содержащий ссылки; Я отправляю этот код …

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

throw firebug я вижу, что теги ссылок удалены, код становится таким же

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

Мне нужен этот сценарий, после того как я запретил человеку, который нарушил правила, отправить электронное письмо, чтобы сообщить причину, по которой мы его запретили. В другом почтовом сервисе электронная почта приходит без проблем, какая моя ошибка, извините за мой английский, я покажу часть из сценария для отправки электронной почты, важная …

  // 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 />'; } 

Если вы не делаете что-то в $ body в коде, который вы не разместили здесь, я предполагаю, что причиной этого является wordwrap (). В руководстве php есть функция, которая может помочь пользователю: http://www.php.net/manual/en/function.wordwrap.php#89782

Возможно, это будет поздно, но хорошо, просто подумайте. По крайней мере, это то, что я вижу здесь. В основном я генерирую динамический бюллетень на основе некоторых данных, и когда я нашел внутри строки определенный синтаксис, я должен был заменить его тегом привязки. Во всяком случае, вот он:

Плохое форматирование:

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

Хорошее форматирование:

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

Прямой ответ, используйте двойные кавычки для атрибута href .

Частью проблемы являются длинные строки, но wordwrap() недостаточно для решения этой проблемы.

Письмо может иметь произвольно длинные строки, но они передаются по протоколу, который разрешает только короткие строки. Таким образом, длинные строки должны быть разделены. Строки протокола теги, которые были разделены добавлением =, затем завершают их так, чтобы началось подобное.

 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 

заканчивается таким образом

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

Использование = подобное, хотя означает, что = не может использоваться в вашем сообщении, поэтому его нужно избегать. Поэтому вам нужно заменить = в своем сообщении с = 3D (где 3D – это шестнадцатеричный код для =).

Также целесообразно заменить любые управляющие символы (с кодом ascii <32) с = xx и с кодом ascii более 126. Я использую эти функции для этого, вам просто нужно сделать $message=encodeText($message) перед отправкой, и проблема должна исчезнуть.

 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; } в 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; } . 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; } 

Попробуйте это, используйте stripslashes() с телом электронной почты, и он должен работать отлично

 $body= stripslashes($mail_message);