SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot santanu's Avatar
    Join Date
    Oct 2003
    Location
    india
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 "

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    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

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    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

  4. #4
    SitePoint Zealot santanu's Avatar
    Join Date
    Oct 2003
    Location
    india
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    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

  6. #6
    SitePoint Addict
    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! 

  7. #7
    SitePoint Zealot santanu's Avatar
    Join Date
    Oct 2003
    Location
    india
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I fix it as
    PHP Code:
    $crlf "\r\n"
    I run the script once get junk message.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •