# Adding HTML to $\_POST elements in email

**URL:** <https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216>\
**Category:** programming\
**Created:** [March 24, 2006, 6:17pm UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216 "2006-03-24T18:17:06Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![wbarrett26](https://avatars.discourse-cdn.com/v4/letter/w/e9a140/32.png) [@wbarrett26](https://forum.kirupa.com/u/wbarrett26)\
**Post date:** [March 24, 2006, 6:17pm UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216/1 "2006-03-24T18:17:06Z")

</div>

I have read through a lot of threads and have found a great deal of information but still having trouble. I want to have a confirmation email sent to people come up in HTML format. I have no problem making regular text come up with HTML attributes but am having no luck with information being retrieved from the Form.

I want the following to have html charteristics:  
$message .="First Name: " .$\_POST[‘firstname’]

You guys have never let me down. Thanks in Advance.  
-wbarrett26

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [March 24, 2006, 6:24pm UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216/2 "2006-03-24T18:24:28Z")

</div>

I’m not sure i’m clear here, what is it you need to be formatted in HTML?

Whate exactly are you referring to as “html characteristics”?

---

<div class="post-metadata">

**Author:** ![SlowRoasted](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@SlowRoasted](https://forum.kirupa.com/u/SlowRoasted)\
**Post date:** [March 24, 2006, 6:28pm UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216/3 "2006-03-24T18:28:09Z")

</div>

Just a stab at it, try defining another variable first.

```php

$firstname = $_POST['firstname'];

$message = "First Name: " . $firstname;

```

---

<div class="post-metadata">

**Author:** ![wbarrett26](https://avatars.discourse-cdn.com/v4/letter/w/e9a140/32.png) [@wbarrett26](https://forum.kirupa.com/u/wbarrett26)\
**Post date:** [March 24, 2006, 7:39pm UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216/4 "2006-03-24T19:39:57Z")

</div>

a user will fill out a form putting in thier name and other general info.  
a confirmation email is sent to them with the info they submitted.  
I can get the general text to come up with html, ie. color size changes, however the fields that are retrieved from the form are only coming up a plain text. I have used a few examples from the forum and other sites as a guide but had no luck.

original confirmation code

```php

function mailuser() {
$to=$_POST['email'];
$subject="Acknowledgement";
$message ="This email confirms your registration."."
";
$message .=""."
";
$message .="First Name: " .$_POST['firstname'] ."
";
$message .="Last Name: " .$_POST['lastname']."
";
$message .="Email Address: " .$_POST['email']."
";
$message .=""."
";
$message .="If there are any errors, please go back to the registration site and re-submit your information."."
";
$headers = "From:". "Registrar";
$headers .= "<registrar@site.com>" ."
";
mail($to, $subject, $message, $headers);
}
?>

```

new confirmation email, not complete

```php

function mailuser() {
$to=$_POST['email'];
$subject="Acknowledgement";
$message = <<<EOF
<html>
	<body bgcolor="#FFFF99" align="center">
        <font face="Arial, Helvetica, sans-serif" color="#000099">
	This email confirms your registration.<br>
	</font>
	</body>
</html>
EOF;
$message .="Last Name: " .$_POST['lastname']."
";
$message .="Email Address: " .$_POST['email']."
";
$message .=""."
";
$message .="If there are any errors, please go back to the registration site and re-submit your information."."
";
$headers = "From:". "Registrar";
$headers .= "<registrar@site.com>" ."
";
$headers .= "Content-type: text/html
";
mail($to, $subject, $message, $headers);
}
?>

```

I would like a way that i could make those POST elements to be in a format other then plain text, either in color or a different font style but when i try to add html code either the POST items would disappear or just not take on HTML styles

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [March 24, 2006, 7:42pm UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216/5 "2006-03-24T19:42:55Z")

</div>

You have to designate the mime type of the e-mail as html

---

<div class="post-metadata">

**Author:** ![wbarrett26](https://avatars.discourse-cdn.com/v4/letter/w/e9a140/32.png) [@wbarrett26](https://forum.kirupa.com/u/wbarrett26)\
**Post date:** [March 24, 2006, 8:31pm UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216/6 "2006-03-24T20:31:47Z")

</div>

even if i use the following i still have a problem  
"MIME-Version: 1.0  
" .  
“Content-type: text/html; charset=iso-8859-1”);

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [March 24, 2006, 9:00pm UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216/7 "2006-03-24T21:00:11Z")

</div>

have ytou tried simplifying it an just making the entire e-mail and header a string?

---

<div class="post-metadata">

**Author:** ![Ankou](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ankou/32/1351_2.png) [@Ankou](https://forum.kirupa.com/u/Ankou)\
**Post date:** [March 24, 2006, 9:58pm UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216/8 "2006-03-24T21:58:24Z")

</div>

> [@wbarrett26](#):
>
> new confirmation email, not complete
> 
> ```php
> 
> function mailuser() {
> $to=$_POST['email'];
> $subject="Acknowledgement";
> $message = <<<EOF
> <html>
> <body bgcolor="#FFFF99" align="center">
> <font face="Arial, Helvetica, sans-serif" color="#000099">
> This email confirms your registration.<br>
> </font>
> </body>
> </html>
> EOF;
> $message .="Last Name: " .$_POST['lastname']."
> ";
> $message .="Email Address: " .$_POST['email']."
> ";
> $message .=""."
> ";
> $message .="If there are any errors, please go back to the registration site and re-submit your information."."
> ";
> $headers = "From:". "Registrar";
> $headers .= "<registrar@site.com>" ."
> ";
> $headers .= "Content-type: text/html
> ";
> mail($to, $subject, $message, $headers);
> }
> ?>
> 
> ```

Just a guess here, but you have your HTML in the $message variable, which when you originally set it has the opening and closing HTML tags. You then append to the end of that string all the information you want from $\_POST. Try putting that infomation inside the start and end HTML tag:

```php

function mailuser() {
$to=$_POST['email'];
$subject="Acknowledgement";
$message = <<<EOF
<html>
    <body bgcolor="#FFFF99" align="center">
        <font face="Arial, Helvetica, sans-serif" color="#000099">
    This email confirms your registration.<br>
EOF;

$message .="Last Name: " .$_POST['lastname']."
";
$message .="Email Address: " .$_POST['email']."
";
$message .=""."
";
$message .="If there are any errors, please go back to the registration site and re-submit your information."."
";

$message .= "
    </font>
    </body>
 </html>";

$headers = "From:". "Registrar";
$headers .= "<registrar@site.com>" ."
";
$headers .= "Content-type: text/html
";
mail($to, $subject, $message, $headers);
}
?>

```

BTW - I didn’t check the code, you may need to change the "  
" to \<br\> if the "  
" is inside the HTML code.

---

<div class="post-metadata">

**Author:** ![wbarrett26](https://avatars.discourse-cdn.com/v4/letter/w/e9a140/32.png) [@wbarrett26](https://forum.kirupa.com/u/wbarrett26)\
**Post date:** [March 25, 2006, 12:13am UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216/9 "2006-03-25T00:13:37Z")

</div>

when i do that it wont retrieve the variables form the form. I thought someone might of know how to do it with a command like print

```php

print("<div align=\"center\" class=\"style12\">First Name</div>");

```

---

<div class="post-metadata">

**Author:** ![SlowRoasted](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@SlowRoasted](https://forum.kirupa.com/u/SlowRoasted)\
**Post date:** [March 25, 2006, 1:00am UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216/10 "2006-03-25T01:00:07Z")

</div>

> have ytou tried simplifying it an just making the entire e-mail and header a string?

I agree, sometimes that makes it work. Not sure why.

---

<div class="post-metadata">

**Author:** ![Voccart](https://avatars.discourse-cdn.com/v4/letter/v/ea5d25/32.png) [@Voccart](https://forum.kirupa.com/u/Voccart)\
**Post date:** [March 25, 2006, 11:45am UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216/11 "2006-03-25T11:45:47Z")

</div>

As Ankou already posted in here – your hangin your message at the end of that html block.

Did you try something like this?

```php
<?
mailuser($_POST['lastname'],$_POST['email']);
function mailuser($lastName,$to) { 
$myEmail = "registrar@site.com";
$myName = "myWebpageName";
$subject= "Acknowledgement"; 
$author = "Last Name: " .$lastName; 
$authorEmail ="Email Address: " .$to; 
$myMessage ="If there are any errors, please go back to the registration site and re-submit your information."; 
$headers = "From: ".$myName."<".$myEmail.">
"; 
$headers .= "MIME-Version: 1.0
"; 
$headers .= "Content-type: text/html
"; 
$message = <<<EOF
<html>
<body bgcolor="#FFFF99">
<p align="center">
<font face="Arial, Helvetica, sans-serif" color="#000099">
<i>This email confirms your registration.</i><br>
$author<br><u>$authorEmail</u><br><br><b>$myMessage</b>
</font>
</p>
</body>
</html>
EOF;
mail($to, $subject, $message, $headers); 
} 
?>

```

---

<div class="post-metadata">

**Author:** ![Ankou](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ankou/32/1351_2.png) [@Ankou](https://forum.kirupa.com/u/Ankou)\
**Post date:** [March 25, 2006, 4:52pm UTC](https://forum.kirupa.com/t/adding-html-to--post-elements-in-email/183216/12 "2006-03-25T16:52:20Z")

</div>

I hadn’t noticed the mail() function was inside a function, probably best practice to actually pass the data to your function like Voccart has shown.

Depending on a number of factors you may be able to call $\_POST[] inside a function and get the value stored in the variable. Depends on the set up of your server and registered globals/superglobals (one or both, I forget at the moment :shifty:).
