Remove <a> tag using php and leave only <td> text

Asked

Viewed 66 times

0

I am using Phpmailer to send emails, but in the body of the email there is a field (address) that is coming as a link (for maps) to the recipient.

I’ve used strip_tags() but it hasn’t solved. Locally it works, but when testo online it doesn’t work.

Code:

 $end = $_POST['endereco'];
 $enderecoFormatado= strip_tags($end, '<a>');

 $corpo = "<h1><table>       
    <tr>
      <td>Endereco: </td>
      <td>
        $enderecoFormatado
      </td>
    </tr>        
  </table>";


 $corpo = utf8_decode($corpo);
 $mail->msgHTML($corpo);
  • It may be that the email client detects Urls and turns them into links.

  • And there’s no way I can narrow it down? (Fiddling with my code of course) Somehow only getting the text to him?

1 answer

1


In general there is no way to avoid this, because the email client automatically adds links when it finds valid Urls in the message body.

However, there is a trick that cheat system and does not add links. Just put addresses (Urls) between tags <a></a> (without href or anything, just <a>). Example:

<a>http://www.site.com</a>

Even works with email addresses:

<a>[email protected]</a>

Obs.: Tested on Gmail and Hotmail successfully.

  • I did several tests and did not come as link. Vc tested in Gmail?

  • In my domain

  • Yes, the answer is that there is no way to avoid it. I just presented a way that works at least in Gmail and Hotmail.

  • As far as I know, only in $mail->IsHTML(false); then everything goes as text

  • It could be, but only if it’s pure text.

  • It worked here man, thank you so much for the tip.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.