For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > December 2004 > trying to send html file as attachment









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author trying to send html file as attachment
Aaron Whiffin

2004-12-03, 3:57 pm


I'm having a nightmare trying to send an email with an html file (based on
the server) along with a message (either as text or html). Does anyone know
of any scripts or functions that could do this.

Alternatively maybe someone can tell me why this code is skipping the first
20 or so lines of the html file...

function sendmail ($from_name, $from_email, $to_name, $to_email, $subject,
$text_message="", $html_message, $attachment=""){

$from = "$from_name <$from_email>";
$to = "$to_name <$to_email>";
$main_boundary = "----=_NextPart_".md5(rand());
$text_boundary = "----=_NextPart_".md5(rand());
$html_boundary = "----=_NextPart_".md5(rand());
$headers = "From: $from\n";
$headers .= "Reply-To: $from\n";
$headers .= "X-Mailer: Kitchen Calendars\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type:
multipart/mixed;\n\tboundary=\"$main_boundary\"\n";
$message .= "\n--$main_boundary\n";
$message .= "Content-Type:
multipart/alternative;\n\tboundary=\"$text_boundary\"\n";
$message .= "\n--$text_boundary\n";
$message .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\n";
$message .= "Content-Transfer-Encoding: 7bit\n\n";
$message .= ($text_message!="")?"$text_message":"Text portion of HTML
Email";
$message .= "\n--$text_boundary\n";
$message .= "Content-Type:
multipart/related;\n\tboundary=\"$html_boundary\"\n";
$message .= "\n--$html_boundary\n";
$message .= "Content-Type: text/html; charset=\"ISO-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n\n";
$message .= str_replace ("=", "=3D", $html_message)."\n";
if (isset ($attachment) && $attachment != "" && count ($attachment) >= 1)
{
for ($i=0; $i<count ($attachment); $i++)
{
$attfile = $attachment[$i];
$file_name = basename ($attfile);
$lines = file($attfile);

$fcontent = "";
foreach ($lines as $line_num => $line) {
$fcontent.= $line;
}
$message .= "\n--$html_boundary\n";
$message .= "Content-Type: text/html; charset=\"ISO-8859-1\"\n";
// $message .= "Content-Transfer-Encoding: quoted-printable\n\n";
// $message .= "Content-Disposition: attachment;
filename=\"$file_name\"\n";
// $message .= "Content-ID: <$file_name>\n\n";
$message .= $fcontent;
}
}
$message .= "\n--$html_boundary--\n";
$message .= "\n--$text_boundary--\n";
$message .= "\n--$main_boundary--\n";
mail ($to, $subject, $message, $headers);
// echo "<pre>\n\n\n".$headers.$message."\n\n\n</pre>";
}

$html_message=
$html_message_header.$main_message_printer.$html_message_footer;

$attachment = Array($filename);

sendmail ($emailfromname, $emailfrom, "Printers", $printeremail,
$printersubject, "Text Section", $html_message, $attachment);


Thanks
Alex


Good Man

2004-12-03, 3:57 pm

"Aaron Whiffin" <aaron@nospam.com> wrote in
news:35Jqd.427$Ym2.259@newsfe2-gui.ntli.net:

> I'm having a nightmare trying to send an email with an html file
> (based on the server) along with a message (either as text or html).
> Does anyone know of any scripts or functions that could do this.


The definitive:

http://www.phpclasses.org/browse/package/9.html




Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com