By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,742 Members | 773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,742 IT Pros & Developers. It's quick & easy.

can't see email BODY when sending email with attachment

P: 37
Hy all....
I tried several functions found on the internet and i don't seem to figure what the problem is... this is one of the example i tryied
Expand|Select|Wrap|Line Numbers
  1. function sendMail($sendto, $subject, $message, $from, $filesToAttach=NULL)
  2. {
  3.     $i=0;    
  4.     $mime_boundary = md5(time());
  5.     $htmlalt_mime_boundary = $mime_boundary."_htmlalt"; //we must define a different MIME boundary for this section
  6.  
  7.     $msg = "--".$mime_boundary."\r\n";    
  8.       $msg .= "Content-Type: multipart/alternative; boundary=\"".$htmlalt_mime_boundary."\"\r\n\r\n";
  9.       # HTML Version
  10.       $msg .= "--".$htmlalt_mime_boundary."\r\n";
  11.       $msg .= "Content-Type: text/html; charset=iso-8859-1\r\n";  
  12.       $msg .= "Content-Transfer-Encoding: 8bit\r\n";
  13.      $msg .= $message."\r\n\r\n";
  14.  
  15.   //close the html/plain text alternate portion
  16.   $msg .= "--".$htmlalt_mime_boundary."--\r\n\r\n";
  17.  
  18.  
  19.     while (isset($filesToAttach[$i]))
  20.     {    
  21.         $fileSize = filesize($filesToAttach[$i]);
  22.         $fileType = filetype($filesToAttach[$i]);
  23.  
  24.         // get the content of the file in a string
  25.         $PtrAttachedFile = fopen($filesToAttach[$i],"r");
  26.         $StrAttachedFile = fread($PtrAttachedFile, $fileSize);
  27.         fclose($PtrAttachedFile);
  28.  
  29.         //base64 encoding. Because the file must be in this format to be sent with a mail client
  30.         $FileToAttach64 = base64_encode($StrAttachedFile);
  31.         //RFC 2045 norm 
  32.         $FileToAttach64 = chunk_split($FileToAttach64, 64 , "\r\n");
  33.  
  34.         //Creation of the header. The "--some random text " string is to mark the file to send. It is used later in the $sender.
  35.         $HeaderAttachedFile = "\r\n--".$mime_boundary."\r\nContent-Type: ".$fileType.";\r\n name=\"".$filesToAttach[$i]."\"\r\n"."Content-Transfer-Encoding: base64\r\nContent-Disposition: attachment;\r\n filename=\"".$filesToAttach[$i]."\"\r\n\r\n";
  36.  
  37.         // we specify the attachement in the recipient 
  38.         $msg .="\r\n".$HeaderAttachedFile.$FileToAttach64;
  39.         $i++;
  40.     }    
  41.  
  42.     $msg .= "--".$mime_boundary."--\r\n\r\n";
  43.  
  44.     $sender .= "MIME-Version: 1.0\nContent-Type: multipart/mixed;".chr(13).chr(10).chr(9)."boundary=\"".$mime_boundary."\"\n";
  45.     $a=mail($sendto, $subject, $msg, $sender);
  46.  
  47.     return $a;
  48. }
  49.  
when i receive the email I only see the subject and the attachments... I don't have any ideea why can't I see the body.
If anybody can point out to what i am doing wrong, i will be gratefull
thanks
Oct 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: 69
I haven't tried multipart mime on my own. I use http://pear.php.net/packages.php?catpid=14&catname=Mail and I highly recommend it. Whenever I've tried to build my own email modules, it works on 80% of stuff and then AOL can't see stuff (can you believe there are dopes still paying them?) or Outlook has a problem (as does all Microsoft stuff). Using PEAR though takes care of all of them (that I've experienced, anyway).
Oct 19 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.