Problems with email script:

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gpig
Forum Newbie
Posts: 15
Joined: Sat Apr 17, 2004 2:52 am

Problems with email script:

Post by gpig »

I need to send attachments, the first one worked with outlook but had problems with other clients(spitting out garbage encoded nonsense together with the emailbody), including webclients. The second worked on web-email clients like hotmail, but not on outlook, still have to test it on other mail-clients.

Here is some snippets of each:
Mail Manage EX:
$Headers = "From: $SendFrom\n";
$Headers .= "Reply-to: $SendFrom\n";
$Headers .= "Return-Path: $SendFrom\n";
if ($CC)
$Headers .= "cc: $CC\n";
$Headers .= "X-Mailer: My PHP Mailer\n";
$Headers .= "MIME-Version: 1.0\r\n";
if ($AttachmentFields and ($ATTACH[0][0] or $ATTACH[1][0] or $ATTACH[2][0]))
$Headers .= "Content-Type: multipart/mixed; charset=\"iso-8859-1\"; boundary=\"$MimeBoundary\";\n\n";
else
$Headers .= "Content-Type: multipart/alternative; charset=\"iso-8859-1\"; boundary=\"$MimeBoundary\";\n\n";
$Headers .= "This is a multi-part message in MIME format.\n\n";

if ($TextEmails == "1")
{
$Content .= "--$MimeBoundary\n";
$Content .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$Content .= "Content-Transfer-Encoding: 8bit\n\n";
$Content .= $EMAIL['textemail']."\n\n";
}
if ($HtmlEmails == "1")
{
$Content .= "--$MimeBoundary\n";
$Content .= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$Content .= "Content-Transfer-Encoding: 8bit\n\n";
$Content .= $EMAIL['htmlemail']."\n\n";
}
if ($AttachmentFields)
{
for ($x=0;$x<count($ATTACH);$x++)
{
$TmpFile = "data/".$ATTACH[$x][0];
@copy($ATTACH[$x][1],"$TmpFile");
$fa = @fopen ($TmpFile,'r');
$FileContent = @fread($fa,filesize($TmpFile));
@fclose($fa);
$FileContent = chunk_split(base64_encode($FileContent));

$Content .= "--$MimeBoundary\n";
$Content .= "Content-Type: application/octetstream;\n name=\"".$ATTACH[$x][0]."\"\n";
$Content .= "Content-Transfer-Encoding: base64\n";
$Content .= "Content-Disposition: attachment;\n filename=\"".$ATTACH[$x][0]."\"\n\n";
$Content .= $FileContent."\n";
@unlink($TmpFile);
}
}
$Content .= "--$MimeBoundary--\n\n\n";



The other :
Red Dot Form Processor:
$message_part.= 'Content-Transfer-Encoding: base64'."\n";
$message_part.= 'Content-Disposition: attachment; filename = "'.$this->parts[$i]['name']."\"\n\n";
$message_part.= chunk_split(base64_encode($this->parts[$i]['body']))."\n";

and elsewhere this
$ctype = $attributes['type'];
$origname = $attributes['name'];
$attachment = fread(fopen(stripslashes($$file), 'r'), filesize(stripslashes($$file)));

$mail->add_attachment($attachment, $origname, $ctype);
$num_attachments++;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

headers need \r\n for end of line markers... not \n\n.. after that.. I dunno.
Post Reply