Dave Homer
Dave Homer

Reputation: 168

How do you send div's content as email with PHP while preserving the html format?

Let's imagine this simple, I have a div (myDiv) inside a form which includes this content:

<div id=myDiv>Hi Same, please click <a href="http://www.test.com">Click here</a></div>

Now I need a php script that will send this div to someones email exactly keeping the proper html format like this:

Hi Same, Please click Click here

The problem is when I have this content in a textbox it sends it all as text. I need to send the div content.

Upvotes: 0

Views: 1355

Answers (3)

Viktor S.
Viktor S.

Reputation: 12815

As you are using free service of formtoemail.com, you should have file you downloaded from their website. Find this line there:

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

and add right before it

$headers .= PHP_EOL;
$headers .= "Content-type: text/html;";

so finaly you will have:

$headers .= PHP_EOL;
$headers .= "Content-type: text/html;";
mail($my_email,$subject,$message,$headers);

Upvotes: 1

max
max

Reputation: 102343

You need to send the email with a content-type=text/html header.

This tells the email client to render the email as HTML.

Exactly how you do that depends on if you are using the built in php functions or a library such as swiftmailer or phpmailer.

Upvotes: 1

Naryl
Naryl

Reputation: 1888

you can use PHPMailer, if you use this method:

$mail->IsHTML(true);

The message will be send as HTML, so it should work.

Upvotes: 1

Related Questions