473,378 Members | 1,426 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,378 software developers and data experts.

email with multiple attachments

30
Hi ,I need my php program to send an email with multiple attachments.
The following code only sends one attatchment even though I am attaching 2 files.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once "Mail.php"; // PEAR Mail package
  3. require_once ('Mail/mime.php'); // PEAR Mail_Mime packge
  4. $thedate="20100907";
  5. $from = "thinus <167677690@nwu.ac.za>";
  6. $to = "thinus <1236767690@nwu.ac.za>";
  7. $subject = 'Test mime message with an attachment';
  8. $headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
  9. $text = 'Text version of email'; // text and html versions of email.
  10. $html = '<html><body>HTML version of email. <strong>This should be bold</strong></body></html>';
  11. $file1 = "C:/aptana/xampp-win32-1.7.3/xampp/htdocs/besa/RD_Env_ICV5/Report/MtM_Bond_".$thedate."/"."TRI_FP_difference_".$thedate.".pdf"; // attachment
  12. $file2 ="C:/aptana/xampp-win32-1.7.3/xampp/htdocs/besa/RD_Env_ICV5/Report/MtM_Bond_".date("Ymd",strtotime("+1 days",$thedate))."/"."TRI_FP_difference_".date("Ymd",strtotime("+1 days",$thedate)).".pdf";
  13. $crlf = "\n";
  14. $mime = new Mail_mime($crlf);
  15. $mime->setTXTBody($text);
  16. $mime->setHTMLBody($html);
  17. $mime->addAttachment($file1,'pdf');
  18. $mime->addAttachment($file2,'pdf');
  19.  
  20. $body = $mime->get();
  21. $headers = $mime->headers($headers);
  22. $host = "scanmail.nwu.ac.za";
  23. $username = "bwi67e";
  24. $password = "b53$";
  25. $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true,
  26. 'username' => $username,'password' => $password));
  27. ////////////////////////////////////////
  28. $mail = $smtp->send($to, $headers, $body);
  29.  
  30. if (PEAR::isError($mail)) {
  31. echo("<p>" . $mail->getMessage() . "</p>");
  32. }
  33. else {
  34. echo("<p>Message successfully sent!</p>");
  35. }
  36. ?>
  37.  

Please advise.
Oct 5 '10 #1
4 5217
kovik
1,044 Expert 1GB
Which attachment gets sent? The first attachment or the second one? And can you give us an example of the raw headers in the e-mail that was received? (censor out personal info, like your e-mail address)
Oct 5 '10 #2
Tinus
30
Hi

file1 is being sended as the attatchment.
I am not sure what you mean with raw headers.
The headers I can view in the mail is as follow.
From : me@skl.com
To:me@skl.com
subject:Test mime message with an attachment
Oct 6 '10 #3
kovik
1,044 Expert 1GB
There should be a lot more than that if you are sending file attachments. What mail application do you use to view your mail? They all have means of displaying detailed headers.
Oct 6 '10 #4
Tinus
30
Thanks for the help.

It is working now:

Expand|Select|Wrap|Line Numbers
  1. $headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
  2. $text = 'Text version of email'; // text and html versions of email.
  3. $html = '<html><body>HTML version of email. <strong>This should be bold</strong></body></html>';
  4. $file1 = "C:/aptana/xampp-win32-1.7.3/xampp/htdocs/besa/RD_Env_ICV5/Report/MtM_Bond_".date('Ymd',$MyToday)."/"."TRI_FP_difference_".date('Ymd',$MyToday).".pdf"; // attachment
  5. $crlf = "\n";
  6. $mime = new Mail_mime($crlf);
  7. $mime->setTXTBody($text);
  8. $mime->setHTMLBody($html);
  9. $mime->addAttachment($file1,'pdf');
  10. // Add a second attachment
  11. $file2 ="C:/aptana/xampp-win32-1.7.3/xampp/htdocs/besa/RD_Env_ICV5/Report/MtM_Bond_".date('Ymd',$MyToday)."/"."TRI_FP_difference_".date("Ymd",strtotime("+1 days",$MyToday)).".pdf"; 
  12. echo $file2;
  13. //file3
  14. $mime->addAttachment($file2,'pdf');
  15. $file3 ="C:/aptana/xampp-win32-1.7.3/xampp/htdocs/besa/RD_Env_ICV5/Report/MtM_Bond_".date('Ymd',$MyToday)."/"."TRI_FP_difference_".date("Ymd",strtotime("+2 days",$MyToday)).".pdf"; 
  16. echo 'file3:'.$file3;
  17. $mime->addAttachment($file3,'pdf');
  18. //do not ever try to call these lines in reverse order
  19. $body = $mime->get();
  20. $headers = $mime->headers($headers);
  21. $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true,
  22. 'username' => $username,'password' => $password));
  23.  
Oct 7 '10 #5

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

Similar topics

5
by: paii, Ron | last post by:
How do I setup a email with attachment for preview but require the user to push the SEND button in Outlook. I have the following function but it sends the email without the sender ever seeing it. ...
1
by: nabil m | last post by:
hi i have 5 checkboxes i would like to when the user click on 1 or multiple checkbox i would like to email 1 or multiple files attachments to them ex: mailMsg.Attachments.Add(myAttachment+i); but...
2
by: EdWhyatt | last post by:
Hi all, I hope there is someone out there who can help me out - it has to be something obvious. I am simulating mail traffic, and want to include multiple attachments to my mail. I have created...
1
by: mike11d11 | last post by:
If someone could help me, I need to be able to send attachments from my access database that I have created. This database runs queries then generates a report off the queries from underlying...
4
by: Mark | last post by:
I need to send an email with vb.net and I must be able to include multiple attachments. When I use mailmessage, it says that the "To" is read only. Any help?
8
alpnz
by: alpnz | last post by:
Hi, I have a need to send snap reports to various shipping agents. E.g. A PalletCard, A FreightNote, A Consignment Advice, and an Export declaration of Conformity. It is easy enough to code a...
5
by: Kosmos | last post by:
I have traveled the world and the seven seas and I have yet to come up with an answer to this question.... So I'm adding an attachment to an email from access... The following is the code: ...
1
by: Drews | last post by:
Many thanks to PuppyDogBuddy or the reference to code samples to send an email and an attachment from within Access, all up and running. However I'm having trouble adding multiple attachments....
16
bre1603
by: bre1603 | last post by:
I have a continuous form in Access 2007 that lists contacts for different agencies. Each record has a checkbox that I can use to generate a mass email to all selected contacts – it’s generic with no...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.