PHP Send Mail (HTML) Script
Line No | Coding |
1 | <?php |
2 | $to = 'user1@OtherDomain.com' . ','; //Specify Multiple Recipients |
3 | $to .= 'user2@OtherDomain.com'; |
4 | $subject = 'My PHP Email'; //Specify Email Subject |
5 | $message = ' |
6 | <html> |
7 | <head> |
8 | <title></title> |
9 |
</head> |
10 | <body> |
11 | <p>Hello Exabytes,</p> |
12 | <h2>My Testing HTML Email!</h2> |
13 | </body> |
14 | </html>'; //Specify Email Message |
15 | $headers = 'MIME-Version: 1.0' . "\r\n"; |
16 | $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; |
17 | //To send HTML mail, the Content-type header must be set |
18 | $headers .= 'From: user<user@MyDomain.com>' . "\r\n"; //Specify Sender |
19 | $headers .= 'Bcc: user2<user2@mail.com>' . "\r\n"; //Specify Bcc User |
20 | mail($to, $subject, $message, $headers); //sent it |
21 | ?> |
Line No | Explanation |
1 | Open PHP tag |
2 - 3 |
PHP Mail Proties: Recipients |
4 |
PHP mail properties: Email Subject |
5 - 14 |
HTML email content |
15 - 19 |
Set PHP mail properties |
20 | Sent Mail |
21 |
Close PHP Tag |
Sample Coding:
--------------------------------------------------
<?php
$to = 'user1@OtherDomain.com' . ','; //Specify Multiple Recipients
$to .= 'user2@OtherDomain.com';
$subject = 'My PHP Email'; //Specify Email Subject
$message = '
<html>
<head>
<title></title>
</head>
<body>
<p>Hello Exabytes,</p>
<h2>My Testing HTML Email!</h2>
</body>
</html>
'; //Specify Email Message
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//To send HTML mail, the Content-type header must be set
$headers .= 'From: Exabytes <user@MyDomain.com>' . "\r\n"; //Specify Sender
$headers .= 'Cc: user<user1@mail.com>' . "\r\n"; //Specify CC user
$headers .= 'Bcc: user2<user2@mail.com>' . "\r\n"; //Specify Bcc User
mail($to, $subject, $message, $headers); //sent it
?>
---------------------------------------------------------------