I have read through the manual on php dot net, and a number of tutorials around the net, however when I create an email and attempt to attach a file, I always get the hex (textual) representation, rather then having the file be attached.
Below is a test that I completed, hard coding all the values necessary to test if it was miscellaneous beginning reasons why i was having difficulty -
-
$path = "/path/to/Test_file.pdf";
-
$name = "Test_file.pdf";
-
$mime_type = "application/pdf";
-
-
$boundary = "VS". md5(uniqid(time()));
-
$mime = sprintf("--%s%s", $boundary, "\n");
-
-
$mime .= sprintf("Content-Type: %s; name=\"%s\"%s", $mime_type, $name, "\n");
-
$mime .= sprintf("Content-Transfer-Encoding: %s%s", "base64", "\n");
-
$mime .= sprintf("Content-Disposition: attachment; filename=\"%s\"%s", $name, "\n\n");
-
-
$file = fopen($path, 'rb');
-
if( !$file )
-
{
-
$mime .= "cannot open file\n\n";
-
}
-
else
-
{
-
$data = fread($file, filesize($path));
-
if(!$data) // added for debugging - doesnt show
-
{
-
$mime .= "cannot read file\n\n";
-
}
-
else
-
{
-
$data = chunk_split(base64_encode($data),76,"\n");
-
fclose($file);
-
-
$mime .= sprintf("%s%s",$data,"\n\n");
-
$mime .= sprintf("--%s--%s", $boundary, "\n");
-
$mime .= "file present"; // added for debugging - shows
-
}
-
}
-
-
$to = "myaddress@domain.com";
-
$subject = "Testing Attachments";
-
$headers = "\r\nFrom: site@domain.com\r\n";
-
-
if(!mail($to, $subject,$mime,$headers))
-
{
-
echo "main not sent";
-
}
-
what I receive is all the $mime variables as they should be, but the file gets replaced with the hex equivalent, and the "file present" message at the bottom as I would expect
my question is, what am I doing wrong that its not attaching the file (in this case a pdf) to the email but rather parsing it in the body ?
1 1603 Atli 5,058
Expert 4TB
Hi.
Could it be that the debug message at the bottom is messing this all up?
Anyways, I do not really have much experience with this. I usually prefer using either Swift Mailer or PHPMailer when I need to send complex emails.
Much easier :P
Sign in to post your reply or Sign up for a free account.
Similar topics
by: marsandys |
last post by:
Hello, I have this code below, which I am trying to have it send HTML
formatted mail with embedded images. I can get this to send the mail,
but it spits out a bunch of junk . I know
this should...
|
by: Robbie De Sutter |
last post by:
Hello,
How do I open a new, empty e-mail message from the default e-mail client
whereby the sender is given and a file is attached?
Currently I use the command (vb.net):
---...
|
by: m_evergreen |
last post by:
Errors:
An unhandled exception of type 'System.Web.HttpException' occurred in
system.web.dll
Additional information: Could not access 'CDO.Message' object.
innerexception is "Exception has...
|
by: Cimento Cola |
last post by:
Hello all.
Hope anyone can help me!
I have this form, with:
Please choose your file: (browse)
The main purpose is the user to select a local file and then when he submits
a mail should be...
|
by: Max |
last post by:
hi
I am using System.Web.Mail.MailMessage with System.Web.Mail.SmtpMail to
send mail. now the my question is,
Is it compulsory to add fields smtpauthenticate, sendusername and
sendpassword...
|
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...
|
by: Chitu03 |
last post by:
Hi
I am already send a mail using Php with some attachement into it. My Problem is the attachement file is in my Database(mysql). I don't know how can i get from database and then add to my mail....
|
by: maxxxxel |
last post by:
Hi
Can anyone help me with some asp code , I changed the code to use CDO.message instead of the old cdont.sys to send mail from a ASP webpage which works fine.
Our problem is that when we send...
|
by: sxwend |
last post by:
I am trying to use the following post results (http://www.thescripts.com/forum/thread189759.html) and add another requirement. I need to send the results to just the email addresses that the query...
|
by: deepaks85 |
last post by:
Dear All,
I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |