|
HTML clipboard
You can send email to mutiple persons in one time. This tutorial shows you in
1 file with a normal form. When you submit, this file will be sent an email
immediately to the target emails from your database.
This tutorial require 1 PHP file and 1 table of mySQL database.
- email_to_multiple.php
- Database "tutorial" and table "email_list" with 3 fields:
id(auto_increment), name(varchar, 50), email (varchar, 50) and put some
records into this table. (directly by phpMyAdmin) as below;
email_to_multiple.php
Source Code :
<?
if($Submit){
$subject=$_POST['subject'];
$note=$_POST['note'];
$sender="webmaster@localhost";
echo "Email has been sent to:";
mysql_connect("localhost","","");
mysql_select_db("tutorial");
$rs=mysql_query("select * from email_list order by id asc");
while($row=mysql_fetch_assoc($rs)){
$to=$row['email'];
$mail_from="From:$email n";
$mail_from .="Content-Type: text/html; charset=utf-8 n";
mail($to,$subject,$note,$mail_from);
echo "$row[email]<br>";
}
}else{
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form action="<? echo $PHP_SELF; ?>" method="post"
name="form" id="form">
<table>
<tr>
<td align="right">Subject : </td>
<td><input name="email" type="text" id="email" /></td>
</tr>
<tr>
<td align="right" valign="top">Note : </td>
<td><textarea name="comment" cols="60" rows="5" id="comment"></textarea></td>
</tr>
</table>
<input type="submit" name="Submit" value="Send Email" />
</form>
</body>
</html>
<? } ?>
|