PHP mail() function for counting the emails that are send
Hello
I have th following PHP script to send emails where the email address is
retrieved form a table in database.
I want to count the number of total emails that are to sent and the emails
that have been sent.
Can anyone help me? I have searched the web for this but it was useless
because I couldn't find anything.The code is as follows
<?php
ignore_user_abort(true);
set_time_limit(0);
if(isset ($_POST["send"]))
{
$upload_name=$_FILES["upload"]["name"];
$upload_type=$_FILES["upload"]["type"];
$upload_size=$_FILES["upload"]["size"];
$upload_temp=$_FILES["upload"]["tmp_name"];
$message=nl2br($_POST["msg"]);
$subject = $_POST["subject"];
$nome = $_POST["nome"];
$email = $_POST["email"];
$from = $nome."<".$email.">";
if($message==""||$subject==""||$nome==""||$email=="")
{
echo '<font style="font-family:Verdana, Arial; font-size:11px;
color:#F3363F; font-weight:bold">Please fill all fields</font>';
}
else
{
$fp = fopen($upload_temp, "rb");
$file = fread($fp, $upload_size);
$file = chunk_split(base64_encode($file));
$num = md5(time());
//Normal headers
$headers = "From:".$from."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
// This two steps to help avoid spam
$headers .= "Message-ID: <".gettimeofday()."
TheSystem@".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
// With message
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";
// Attachment headers
$headers .= "Content-Type:".$upload_type." ";
$headers .= "name=\"".$upload_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$upload_name."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--";
$sql = "SELECT * FROM table";
$result = mysql_query($sql,$link);
while($mail = mysql_fetch_assoc($result)){
if($mail['sponsor'] == $_POST['sendto']){
@mail($mail['email'], $subject, $message, $headers);
sleep(20);
}
if($_POST['sendto'] == 2){
@mail($mail['email'], $subject, $message, $headers);
sleep(20);
}
}
fclose($fp);
echo '<font style="font-family:Verdana, Arial; font-size:11px;
color:#333333; font-weight:bold">Mail sent please check inbox and spam
both <br /></font>';
}
}
?>
<html>
<head>
<title>Mail</title>
</head>
<body>
<form id="attach" name="attach" method="post" action="<?php echo
$_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<table>
<tr>
<td>Nome Mittente</td><td>:</td><td><input type="text"
name="nome" id="nome"></td>
</tr>
<tr>
<td>Email Mittente</td><td>:</td><td><input
type="text" name="email" id="email"></td>
</tr>
<tr>
<td>Oggetto</td><td>:</td><td><input type="text"
name="subject" id="subject"></td>
</tr>
<tr>
<td>Message</td><td>:</td><td> <textarea name="msg"
id="msg" cols='40' rows='10'></textarea></td>
</tr>
<tr>
<td>Attachment(word,pdf,foto)<span
class="imp">*</span></td><td>:</td><td><input
type="file" name="upload" id="upload"></td>
</tr>
<tr>
<td>Send to</td><td>:</td><td> <select name='sendto'
id='sendto' >
<option value='----'>-------</option>
<option value='2'>All</option>
<option value='1'>Sponsor</option>
<option value='0'>Non Sponsor</option>
</select></td>
</tr>
<tr>
<td></td><td></td><td><input type="submit"
value="Submit" id="send" name="send"></td>
</tr>
</table>
</form>
</body>
</html>`
No comments:
Post a Comment