How To Send Out a Mass Email With PHP Script
So, how do I send out a mass email using php script ? Follow the tutorial below :1. Create Send Out Mass Email Form
Our first step is to create a form that will be used to send out mass email and this form consists of email boxes destination, message subject and message body. This is following details the html script to create send out a mass email form.Send-Out-Mass-Email-Form.html
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.style2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 16px;
font-weight: bold;
}
-->
</style>
<form name="form1" method="post" action="Send-Out-Mass-Email-PHP-script.php">
<div align="center">
<p class="style2"> Email Massal Form </p>
<table width="40%" border="0">
<tr>
<td width="37%" valign="top" class="style1">To </td>
<td width="4%" valign="top" class="style1">:</td>
<td width="59%" valign="top" class="style1"><label>
<input name="email_list" type="text" id="email_list" size="25">
</label></td>
</tr>
<tr>
<td valign="top" class="style1"> Subject </td>
<td valign="top" class="style1">:</td>
<td valign="top" class="style1"><label>
<input name="mail_subject" type="text" id="mail_subject" size="25">
</label></td>
</tr>
<tr>
<td valign="top" class="style1"> Message </td>
<td valign="top" class="style1">:</td>
<td valign="top" class="style1"><label>
<textarea name="mail_body" cols="35" rows="5" id="mail_body"></textarea>
</label></td>
</tr>
<tr>
<td valign="top" class="style1"> </td>
<td valign="top" class="style1"> </td>
<td valign="top" class="style1"><label>
<input name="sent" type="submit" id="sent" value="sent">
<input type="reset" name="Submit2" value="cancel">
</label></td>
</tr>
</table>
</div>
</form>
To be able to send out a mass email, in email box destination, fill
in your email address goals and separate them with commas (,).Example:
email-1@email1.com,email-2@email2.com,email-3@email3.com, email-4@email4.com
2. Create PHP Script to Send Out a Mass Email
Php script that will be used to create mass email delivery is to use PHP mail() function and PHP explode function to separate email lists goals. More details, please learn how to create a php script to send mass email commands.Send-Out-Mass-Email-PHP-script.php
<?php
$mail_subject=$_POST['mail_subject'];
$email_list=$_POST['email_list'];
$mail_body=$_POST['mail_body'];
$process=explode(",",$email_list);
reset($process);
foreach ($process as $to) {
$sent=mail($to,$mail_subject,$mail_body, "From: youremail@domain.com");
}
if ($sent) {
echo "<b> Email has been successfully sent </b><br><br>";
echo "<b> Message : </b><br>$mail_body";
} else {
echo "Email could not be sent, there may be errors in the e-mail address";
}
?>
Now you already know the php script to