So I can't seem to word the question right - but I would like to know how would you go about changing the way this
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "
";
$Body .= "City: ";
$Body .= $City;
$Body .= "
";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "
";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "
";
looks when it reaches my e-mail. When I receive the e-mail (using it as a contact form), I get this ->
Name: lloan
City: SomeCity
Email: some@email.com
Message: Testing
I tried <strong> $Body .= "Name: ";</strong>
and that didn't work - I also tried it as $Body .= "<strong> Name: </strong>";
and again, nothing. Can anyone point me in the right direction? I really want to learn how to do this - I've googled it a couple of times, but I think it's the way I'm wording my question that's not helping me.
EDIT: So I'm able to do this now - $Body .= "<strong>Name: </strong>";
using the suggestions below of adding the headers and then adding that to the mail() function - however, how do I go about using it on a bigger scale? For example - What if I want to have a colored background or what not - Am I also able to use CSS in this kind of situation? The other questions on SO do not answer this in it's entirety.
Here's how:
$to = 'yourmailtarget@example.com';
$subject = 'Your email subject';
$headers = "From: abc@abc.com
";
$headers .= "Reply-To: no-reply@abc.com
";
$headers .= "CC: abc@abc.com
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: text/html; charset=UTF-8
";
$message = 'Put your html message here<br>';
$message .= "<b>HTML feature is now enabled</b><br>";
$message .= "<table border="1"><tr><td>Hello</td><td>World</td></tr></table>";
$message .= "For the styling, you can use inline styling:<Br>";
$message .= "<span style='color:#FF0000;'>This is red color</span>";
mail($to,$subject,$message,$headers,$parameters);
The most important part to answer your question is this line:
$headers .= "Content-Type: text/html; charset=UTF-8
";
That tells the system to produce the email using the HTML format.
Hope this helps
In the mail function add a parameter headers like this :
$headers = 'MIME-Version: 1.0' . " "; $headers .= 'Content-type: text/html; charset=iso-8859-1' . " ";
and call the mail function like this :
mail($to, $subject, $Body, $headers)
If you would like to format your message (the content of variable $Body), you are free to use as much HTML as you want.
If you want to send HTML email you also need to send a text-only version as not all mail clients support HTML, and some mail systems specifically strip HTML versions.
This means you need a Content-type:multipart
header, and multiple sections with their own headers, each delimited by a specific boundary. The actual format is quote complex, so use a library like swiftmail or PHPMailer