Faizan Qadri
Faizan Qadri

Reputation: 248

Styling of EMAIL in PHP

i am trying to style up my message being sent from the contact form and following is my code i tried to do $message = echo "< hr>"; but the code didn't worked kindly let me know how can i style up my following message like change the texts colour, font size (HTML STYLING)

$message="Name : $name \r\n\n";
$message.="PHONE : $phone \r\n\n";
$message.="Company : $company \r\n\n";
$message.="Comments/Questions : \r\n";
$message.="---------------------------------------------------------------------------\r\n";
$message.= $_POST['message'];

Upvotes: 0

Views: 104

Answers (3)

web2students.com
web2students.com

Reputation: 307

I assume you know all other things, Use this headers in email for html email $headers = "MIME-Version: 1.0" . "\r\n Content-type:text/html;charset=iso-8859-1" . "\r\n"; then you can write html email

$htmlMessage="Your styled message"; mail($to,$subject,$htmlMessage,$headers); But be careful, gmail don't show images due to security reasons. and so html codes may not run and sometimes gmail (others too) may send your email to spam if headers are not correct.

Upvotes: 0

user1233508
user1233508

Reputation:

To use HTML markup in your email, you need to include an additional header in the mail function:

Content-Type: text/html; charset=utf-8

Or, even better, use a library like PHPMailer. That way, you just need to tell it this message is HTML and it will take care of the headers for you.

Edit: forgot to mention, different email clients have very varied CSS support. In general, you should keep the styling to a minimum, test everything in various mail clients, read the helpful articles of people who have already tried... and accept the fact that some mail clients are just a nightmare.

Upvotes: 2

Vaishu
Vaishu

Reputation: 2363

Try this..

$message = "<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Something</title>
</head>
<body>";

$message .="
    Name : $name <br />
    PHONE : $phone $domain<br />
    Company : $company<br />
    Comments/Questions:<br />
    <hr /><br />

</body>
</html>";

Upvotes: 1

Related Questions