473,395 Members | 1,689 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.

problems to use php mail() to attach more than 1 attachment

123 100+
I use below to attach 2 attachment however only the once I check the email,
I can only receive the first atatchment, and the second atatchment are always
name as ATTXxX with 0k only....how come???
ATT00001 (0.0 KB), firstfile.doc (96.6 KB)

thanks.


Expand|Select|Wrap|Line Numbers
  1.     $num = md5(time()); 
  2.     $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";  
  3.  
  4.     //Normal headers 
  5.        $headers  = "From: AAA<ad@aaa.com>\r\n"; 
  6.        $headers  .= "MIME-Version: 1.0\r\n"; 
  7.        $headers  .= "Content-Type: multipart/mixed; "; 
  8.        $headers  .= "boundary=".$num."\r\n"; 
  9.        $headers  .= "--$num\r\n"; 
  10.  
  11.     // This two steps to help avoid spam    
  12.     $headers .= "Message-ID: <".gettimeofday()." TheSystem@".$_SERVER['SERVER_NAME'].">\r\n"; 
  13.     $headers .= "X-Mailer: PHP v".phpversion()."\r\n";    
  14.  
  15.     // With message 
  16.        $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n"; 
  17.        $headers .= "Content-Transfer-Encoding: 8bit\r\n"; 
  18.        $headers .= "".$message."\n"; 
  19.        $headers .= "--".$num."\n";  
  20.  
  21.     /* firstFile */ 
  22.     $fileatt = $_FILES['emailsentmsg']['name']; // Path to the file                  
  23.     $fileatt_type = $_FILES['emailsentmsg']['type']; 
  24.     $fileatt_temp = $_FILES['emailsentmsg']['tmp_name']; 
  25.     $fileatt_size = $_FILES['emailsentmsg']['size']; 
  26.     $fileatt_name = $fileatt; // Filename that will be used for the file as the attachment 
  27.  
  28.     $fp = fopen($fileatt_temp,'rb'); 
  29.     $file = fread($fp, $fileatt_size); 
  30.     $file = chunk_split(base64_encode($file)); 
  31.  
  32.     // Attachment headers 
  33.        $headers .= "--{$mime_boundary}\n" . 
  34.        $headers  .= "Content-Type:".$fileatt_type." "; 
  35.        $headers  .= "name=\"".$fileatt_name."\"r\n"; 
  36.        $headers  .= "Content-Transfer-Encoding: base64\r\n"; 
  37.        $headers  .= "Content-Disposition: attachment; "; 
  38.        $headers  .= "filename=\"".$fileatt_name."\"\r\n\n"; 
  39.        $headers  .= "".$file."\r\n"; 
  40.        $headers  .= "--{$mime_boundary}\n"; 
  41.  
  42.     fclose($fp);
  43.     unset($file);
  44.     unset($fileatt); 
  45.     unset($fileatt_type); 
  46.     unset($fileatt_name);
  47.  
  48.     /* second File */ 
  49.     if ($emailsentmsg0){
  50.     $fileatt = $_FILES['emailsentmsg0']['name']; // Path to the file                  
  51.     $fileatt_type = $_FILES['emailsentmsg0']['type']; 
  52.     $fileatt_temp = $_FILES['emailsentmsg0']['tmp_name']; 
  53.     $fileatt_size = $_FILES['emailsentmsg0']['size']; 
  54.     $fileatt_name = $fileatt; // Filename that will be used for the file as the attachment 
  55.  
  56.     $fp = fopen($fileatt_temp,'rb'); 
  57.     $file = fread($fp, $fileatt_size); 
  58.     $file = chunk_split(base64_encode($file)); 
  59.  
  60.     // Attachment headers 
  61.     //$headers .= "--{$mime_boundary}\n" . 
  62.     $headers  .= "Content-Type:".$fileatt_type." "; 
  63.        $headers  .= "name=\"".$fileatt_name."\"r\n"; 
  64.        $headers  .= "Content-Transfer-Encoding: base64\r\n"; 
  65.        $headers  .= "Content-Disposition: attachment; "; 
  66.        $headers  .= "filename=\"".$fileatt_name."\"\r\n\n"; 
  67.        $headers  .= "".$file."\r\n"; 
  68.        $headers  .= "--{$mime_boundary}\n"; 
  69.  
  70.         fclose($fp);
  71.         unset($file);
  72.         unset($fileatt); 
  73.         unset($fileatt_type); 
  74.         unset($fileatt_name);
  75.     }
  76.  
  77.     $oksent = mail($emailto, $subject, $message, $headers);
Feb 11 '10 #1
3 2832
perhapscwk
123 100+
anyone can help? thanks.
Feb 12 '10 #2
Dormilich
8,658 Expert Mod 8TB
don’t know.

I use the SwiftMailer library for everything that is more than a simple text mail.
Feb 12 '10 #3
Markus
6,050 Expert 4TB
@Dormilich
I second this. PHP's mail() function sucks. Check out SwiftMailer.
Feb 12 '10 #4

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

Similar topics

1
by: praba kar | last post by:
Dear All, I am new to python world. I have pasted my code which I used it to build rfc822 format mails for webbased mailing system task(which is like to yahoo.com web interface). Now I am...
7
by: brigitte | last post by:
Hi, I'm having trouble with a specific e-mail text format attachment ... The requirement is for the attachment to be .txt type and in this format: Label=FieldValue Label=FieldValue...
2
by: GD | last post by:
Hi, An intranet application, with a SMTP mail function that lets users to attach files with emails by selecting files in their local computers (through a file browser component), works perfect on...
5
by: Robert Dufour | last post by:
I am trying to use framework 1.1 - stuck with it. to send emails from a windows form application. The email messages can have attachments, usually two and they can be either text or sounds (wav...
1
by: William Connery | last post by:
Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an...
9
by: deepaks85 | last post by:
Dear Sir, I have created a simple request form which will be mailed to me. Now I want to attach files and send it through that request form. For this I am using the following script: ...
4
by: David C | last post by:
I would like to have an email go to 2 email addresses but when I try it by separating with semicolon or comma it fails. Can anyone help? below is my code (see ToAddress string). Thanks. David...
11
by: Ed Bitzer | last post by:
I have been able using the namespace System.Web.Mail and its method Smtp.mail.send to mail simple text messages to a small group within our 55 and older community. I need help expanding the...
3
by: raj200809 | last post by:
when i m sending mail i received error from symantec Antivirus" Your email message was unable to be sent because your mail server rejected the message 550-5.7.1 the ip you’re using to send mail is...
2
by: sat1983 | last post by:
Hi I am beginner to C Sharp. trying to attach a multiple files to a mail. I can attach a single file or i can create multiple object of an Attachment class and add to a mail attachment object....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.