Re: http://www.php.net/manual/en/function.mail.php#41681
I am using this alternative to mail():
// ORIGINAL FUNCTION FOUND AT [url]http://www.php.net/manual/en/function.mail.php#41681[/url] WITH cc AND bcc MODIFICATIONS BY PHIL POWELL 6/10/2004
function mail_attach($to, $from, $subject, $message, $files = false, $lb="\n", $cc = '', $bcc = '') {
/*----------------------------------------------------------------------------------------------
$to Recipient
$from Sender (like "email@domain.com" or "Name <email@domain.com>")
$subject Subject
$message Content
$files hash-array of files to attach
$lb is linebreak characters... some mailers need \r\n, others need \n
-------------------------------------------------------------------------------------------------*/
$mime_boundary = "<<<:" . md5(uniqid(mt_rand(), 1));
$header = 'From: '. $from;
if ($cc) $header .= $lb . "Cc: $cc";
if ($bcc) $header .= $lb . "Bcc: $bcc";
if (is_array($files)) {
$header.= $lb .
"MIME-Version: 1.0$lb" .
"Content-Type: multipart/mixed;$lb" .
" boundary=\"$mime_boundary\"$lb";
$content = "This is a multi-part message in MIME format.$lb$lb" .
"--$mime_boundary$lb" .
"Content-Type: text/plain; charset=\"iso-8859-1\"$lb" .
"Content-Transfer-Encoding: 7bit$lb$lb";
}
$content .= $message . $lb;
if (is_array($files)) {
$content.= "--$mime_boundary$lb";
foreach ($files as $filename => $filelocation) {
if (is_readable($filelocation)) {
$data = chunk_split(base64_encode(implode('', file($filelocation))));
$content.= "Content-Disposition: attachment;$lb" .
'Content-Type: ' . mime_content_type($filelocation) . " name=\"$filename\"$lb" .
"Content-Transfer-Encoding: base64$lb$lb" .
"$data$lb" .
"--$mime_boundary$lb";
}
}
}
if (mail($to, $subject, $content, $header)) return true;
return false;
}
However, upon attempt to email something (right now, a very small 10K PNG image file), every email is stuck in queue and goes nowhere for up to 10 minutes, meanwhile, the website is stuck WITH IT!
Has anyone successfully ever auto-generated email with attachments, if so, how?
Thanx
Phil