How to send mail in PHP?
- Send mail is a very easy task in PHP –
<?php
$to = 'abc12340@gmail.com,defg12340@gmail.com'; // you can add more than one email address with comma
// mail Subject
$subject = 'Wedding Wishes of Friend';
// mail Message
$email_message = '
<html>
<head>
<title>Wedding Wishes of Friend</title>
</head>
<body>
<p>Wedding Wishes of Friend</p>
<table>
<tr>
<th>Name</th><th>Class</th>
</tr>
<tr>
<td>Ashok</td><td>B.Tech</td>
</tr>
</table>
</body>
</html>
';
// To send HTML mail
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// you can add additional headers
$headers[] = 'To: Ashok <ashok123@example.com>, Rams <rams123@example.com>';
$headers[] = 'From: Wedding Wishes of Friend <weddingpro@example.com>';
$headers[] = 'Cc: ashok12356780@example.com';
$headers[] = 'Bcc: ashok876543210@example.com';
// Mail function
mail($to, $subject, $email_message, implode("\r\n", $headers));
?>
- In the above code, mail( ) is a built in function of PHP language.
- mail($to, $subject, $email_message, $headers); this function requires minimum 4 parameters which is given in code.
- The $email_message variable shows send the HTML mail.
$headers[] = 'To: Ashok <ashok123@example.com>, Rams <rams123@example.com>';
$headers[] = 'From: Wedding Wishes of Friend <weddingpro@example.com>';
$headers[] = 'Cc: ashok12356780@example.com';
$headers[] = 'Bcc: ashok876543210@example.com';
- The header section defines the BCC and CC mails.
How to send mail in PHP