php problem emailer script sends twice, I dont know why!?!
Posted: Mon Apr 19, 2004 9:43 am
Hey guys I posted one earlier about getting my email script to send a file along with the email now its doing that but it is also now sending a second email behind the 1st. This script is perfect other than that. If someone could show me what the problem is I would really appreciate the help.
Thanks guys
#!/usr/local/bin/php
[Edit: Added PHP tags for eyecandy. --JAM][/b]
Thanks guys
#!/usr/local/bin/php
Code: Select all
<?
function sendmsg($to, $subject, $text, $from, $file, $type) {
$content = $file;
$content = chunk_split(base64_encode($content));
$uid = strtoupper(md5(uniqid(time())));
$name = 'report.txt';
$header = "From: $from\nReply-To: $from\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=$uid\n";
$header .= "--$uid\n";
$header .= "Content-Type: text/plain\n";
$header .= "Content-Transfer-Encoding: 8bit\n\n";
$header .= "$text\n";
$header .= "--$uid\n";
$header .= "Content-Type: $type; name="$name"\n";
$header .= "Content-Transfer-Encoding: base64\n";
$header .= "Content-Disposition: attachment;
filename="$name"\n\n";
$header .= "$content\n";
$header .= "--$uid--";
mail($to, $subject, "", $header);
return true;
}
// Load up array with file names!
$handle = opendir('/spooler');
$array_idx = 0;
while (false !== ($file = readdir($handle)))
{
$dir_array[$array_idx] = $file;
$array_idx ++;
}
foreach ($dir_array as $n)
{
if ($n == '.' || $n == '..' || $n == 'bin')
{
// Do Nothing for these
}
else
{
$filename = "/spooler/".$n;
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
//testing text file for ownership
}
else
{
$filename = "/spooler/".$n;
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
$email_to = "tester@testing.com";
$mailto = $email_to;
$subject = "ECA Auto-Reports";
$body = "Your report is attached to this message.";
$from = "mail-bot@elasticcorp.com";
$file = $contents;
$type = "text/.txt";
sendmsg($mailto, $subject, $body, $from, $file, $type);
// remove file from dir
unlink("/spooler/".$n);
}
}
?>