trying to send html file as attachment

From: Aaron Whiffin (aaron_at_nospam.com)
Date: 11/29/04


Date: Mon, 29 Nov 2004 17:34:55 GMT


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



Relevant Pages

  • Re: Total drop down boxes
    ... The first method consists in manually writing the content in the file, either in the HTML file directly or using some automated method on a server. ... The second one consists in writing the mass HTML in a javascript variable, then document.writing the content of this variable on the document. ...
    (comp.lang.javascript)
  • Re: Automating steps to copy URL from IE into Word
    ... Inside an html document, VBScript is contained between script tags. ... you can create an html file and convert it to an hta file ... > webpage document and it would run when the webpage was opened? ... However, if the document is open, it opens a second ...
    (microsoft.public.word.vba.general)
  • Re: web query : part of a table not captured
    ... HTML files have tables and forms. ... RowCount = RowCount + 1 ... Put the HTML code is a HTML file. ... For Each itm In Results ...
    (microsoft.public.excel.programming)
  • Re: web query : part of a table not captured
    ... HTML files have tables and forms. ... RowCount = RowCount + 1 ... save on my PC as a HTML and the macro I generated. ... Put the HTML code is a HTML file. ...
    (microsoft.public.excel.programming)
  • Re: format of txt file lost
    ... Using   to replace the spaces is indeed the correct way to go. ... Server property). ... It looks like you're creating an HTML file. ...
    (microsoft.public.dotnet.languages.csharp)