SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: Problem in mail attachment
-
Oct 9, 2007, 03:07 #1
Problem in mail attachment
Hello All,
I am facing a strange problem. I write a script to send email with attachment. I test it at local machine (windows XP) and it works perfectly. But when i test at server (linux) i gets garbage messages like below.
"--=2145fb7d0a3b884574893ef2e2f25d8brnContent-Type: application/octet-streamrnContent-Transfer-Encoding: base64rnContent-Disposition: attachment
--=_2145fb7d0a3b884574893ef2e2f25d8b--rn "
-
Oct 9, 2007, 03:11 #2
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Can you show us the code?
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Oct 9, 2007, 03:21 #3
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Maybe there some line termination \r\n \n. Normally windows uses \r\n and linux only \n. Would be better if we could see your code.
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Oct 9, 2007, 03:27 #4
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use diff. tyoes here
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
$header .= "--".$uid."--";
include(Mail/mime.php');
$crlf = "rn";
$mime = new Mail_mime($crlf);
$mime->addAttachment($file,'application/octet-stream');
$body = $mime->get();
include ('util/admin/ReportMail.php');
$reportemail = new reportMail;
$reportemail->setBody($body);
$reportemail->setRecipient('To', 'santanu@xyz.com');
$reportemail->setHeader('From', 'webmaster@xyz.com',true);
$reportemail->setHeader('replyto', 'santanu@xyz.com',true);
$reportemail->setHeader('header', $header,true);
$reportemail->setHeader('To', 'santanu@xyz.com',true);
$reportemail->setRecipient('Cc', 'santanu@xyz.com');
$reportemail->setHeader('Cc', 'santanu@xyz.com',true);
$reportemail->send();
echo "send";
}
mail_attachment('more.pdf', "pdf/","","","","","testing....","test mail");
Here i use PEAR to send mail.
-
Oct 9, 2007, 03:32 #5
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Yup, it's the line breaks.
oh, and please put code in [ PHP ] tags, it looks tidier.
I get problems with copying and pasting code in the tags, because it removes line breaks. However - it looks better, and we can spot errors quicker.
PHP Code:function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\n\n";
$header .= "This is a multi-part message in MIME format.\n";
$header .= "--".$uid."\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\n";
$header .= "Content-Transfer-Encoding: 7bit\n\n";
$header .= $message."\n\n";
$header .= "--".$uid."\n";
$header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\n"; // use diff. tyoes here
$header .= "Content-Transfer-Encoding: base64\n";
$header .= "Content-Disposition: attachment; filename=\"".$filename."\"\n\n";
$header .= $content."\n\n";
$header .= "--".$uid."--";
include(Mail/mime.php');
$crlf = "rn";
$mime = new Mail_mime($crlf);
$mime->addAttachment($file,'application/octet-stream');
$body = $mime->get();
include ('util/admin/ReportMail.php');
$reportemail = new reportMail;
$reportemail->setBody($body);
$reportemail->setRecipient('To', 'santanu@xyz.com');
$reportemail->setHeader('From', 'webmaster@xyz.com',true);
$reportemail->setHeader('replyto', 'santanu@xyz.com',true);
$reportemail->setHeader('header', $header,true);
$reportemail->setHeader('To', 'santanu@xyz.com',true);
$reportemail->setRecipient('Cc', 'santanu@xyz.com');
$reportemail->setHeader('Cc', 'santanu@xyz.com',true);
$reportemail->send();
echo "send";
}
mail_attachment('more.pdf', "pdf/","","","","","testing....","test mail");
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Oct 9, 2007, 03:38 #6
- Join Date
- Aug 2005
- Posts
- 207
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
\r\n is correct, it doesn't matter what system your on, the RFC 2049 standard is \r\n, so that is not your problem, the problem is here...
PHP Code:$crlf = "rn"; // missing \ back slashes before r and n!
-
Oct 9, 2007, 03:52 #7
I fix it as
PHP Code:$crlf = "\r\n";
Bookmarks