php Elephant Icon Logo
me@grafxflow

Written by me@grafxflow

02 Oct, 2008

0

1,841

Embedding html in an email with php

Here is the basic code which will allow you to embed html inside an email, with the use of php.

<?php
$from_email = "From: from_email_address\n";
$from_email .= "Content-Type:text/html; charset=\"iso-8859-1\"\n";
$subject = "Form confirmation email";
$message = "<html content to go here code>";
$send_to = "to_email_address";
mail($send_to, $subject, $message, $from_email);
?>

Here is another version including other settings such as Bcc, Urgent Message for reference:

<?php
$from_email = "From: from_email_address\n";
$from_email .= "X-Sender: from_email_address\n";
$from_email .= "X-Mailer: PHP\n"; // mailer
$from_email .= "X-Priority: 1\n"; //1 Urgent Message, 3 Normal
$from_email .= "Content-Type:text/html; charset=\"iso-8859-1\"\n";
$from_email .= "Bcc:user1@example.com, user2@example.com\n";
$from_email .= "Cc:user1@example.com, user2@example.com\n";
$subject = "Form confirmation email";
$message = "<html content to go here code>";
$send_to = "to_email_address";
mail($send_to, $subject, $message, $from_email);
?>

Add comment

Smart Search

131 Following
57 Followers

me@grafxflow

Hull, United Kingdom

I am a Full-stack Developer who also started delving into the world of UX/UI Design a few years back. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!

Follow