Author Topic: Sending HTML Email  (Read 4662 times)

0 Members and 2 Guests are viewing this topic.

Offline peci

  • Supporter
  • **
  • Posts: 1
  • Karma: +0/-0
Sending HTML Email
« on: August 27, 2007, 04:03:48 AM »
This tutorial will show you how to send email with HTML output in PHP.

index.php(form)


Code: [Select]
<form name="myform" action="mail.php" method="POST">

<strong>E-mail</strong><br/>
        <input type=text name="to" size="25"><br>
<strong>Your Message</strong><br/>
        <input type=text name="msg" size="25"><br>

<INPUT TYPE="SUBMIT" VALUE=" Submit">
<INPUT TYPE="RESET" VALUE=" Reset">
</form>


Mail Body - Position, background, font color, font size...


Code: [Select]
$body ='
<html>
<head>
<style>
<!--
body, P.msoNormal, LI.msoNormal
{
background-position: top;
background-color: #336699;
margin-left:  10em;
margin-top: 1em;
font-family: "verdana";
font-size:   10pt;
font-weight:bold ;
color:    "000000";
}
-->
</style>
</head>
</body>
';

Image in e-mail


Code: [Select]
$mailimg = '<img src="http://yoursite.zz/images/sample.jpg"</a>';
To send HTML mail, the Content-type header must be set:


Code: [Select]
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: System Admin <noreply@domain.com>' . "\r\n";





mail.php


Code: [Select]
<?php
$to 
$_POST['to']; 
$msg $_POST['msg'];
$mailimg '<img src="http://phpform.net/tell/images/sample.jpg"</a>';
$body ='
<html>
<head>
<style>
<!--
body, P.msoNormal, LI.msoNormal
{
background-position: top;
background-color: #336699;
margin-left:  10em;
margin-top: 1em;
font-family: "verdana";
font-size:   10pt;
font-weight:bold ;
color:    "000000";
}
-->
</style>
</head>
</body> 
'
;

$headers='MIME-Version: 1.0' "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
$headers .= 'From: System Admin <noreply@domain.com>' "\r\n";
$bodys .= "$msg <br>";
$bodys .= "$mailimg";
$subject .="My HTML Mail";


$body $body $bodys;
mail($to$subject$body$headers);
?>



Rate this Script @ The PHP Resource Index
http://php.resourceindex.com/rate
Rate this Script @ Hot Scripts.com
http://www.hotscripts.com/rate/73170.html
« Last Edit: April 17, 2009, 12:56:00 PM by admin »

 

Related Topics

  Subject / Started by Replies Last post
5 Replies
3741 Views
Last post November 02, 2009, 09:44:59 AM
by djape
3 Replies
3348 Views
Last post January 16, 2009, 07:57:51 PM
by LauraJean
0 Replies
226 Views
Last post January 30, 2010, 08:14:31 AM
by alex