473,395 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

can't see email BODY when sending email with attachment

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
1 1875
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

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

Similar topics

3
by: Paul Lamonby | last post by:
Hi, I am sending a file from the server as an email attachment. The file is being attached no problem and sending the email, but I get an error when I try to open it saying it is corrupt....
2
by: Martin Körner | last post by:
Hi NG, I am using email module for creating mails with attachment (and then sending via smtplib). If the name of the attachment file is longer than about 60 characters the filename is wrapped...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
4
by: rschaeferhig | last post by:
I have an ASP page that uses CDOSYS to send a simple HTML format email with a PDF attachment. When I open the PDF attached to the email it shows up as a blank page. I log into the web server...
3
by: =?Utf-8?B?SHVnaA==?= | last post by:
Hi There, I use follow code to send email inside VB.NET 2005. It does not work well. Error message of "Failure sending email" would occue. However, email was sent out sometimes. I am confused...
1
by: krishan123456 | last post by:
i have tried to send email with attached doc file but when i receive the mail i find the attached file in encoded text instead of actuall attachment.the code that i used to send an email is given...
0
by: prasenjit2007 | last post by:
I have a main form for inputing the (to/from/mesg/file) with the following code:- <html> <body> <table> <tr> <td>To:</td> <td><input type="text" name="to" size="50" ...
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
9
by: SREEDEV | last post by:
I am sending a email with a HTML body from my VB.NET application using SMTP protocol. I am facing a problem when i send a long HTML text as body. Its working perfectly with small HTML body. But that...
7
by: Paridevi | last post by:
Hai , i want to send email in .Net Using OutLook Express,My Project is Web Application using vb.Net 2003 with SQL Server 2000.I have searched a lot in Google, but ican't get any...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.