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

PHP 4.1.1 and Email Attachments

Now I've been working on a script that sends emails with different attachments, including csv, xls, docs, txt, and html/htm files. However when attaching, some information at the top in the txt files are missing, and not only that, doc / xls files are unable to open without a slew of funny characters when running through [PHP]chunk_split(base64_encode($filename))[/PHP] to attach. The attachment is there, the message is there. However opening the applications is a whole different story! The script is below. My suspicion is I'm using a very a outdated version of PHP (hopefully will be upgraded soon!). Could this be the culprit? Otherwise, I'm stumped on the inconsistent handling of attachments using PHP.

[PHP]

if (preg_match("/\.(txt)$/",$filename) ) { $mimetype = "text/txt";
} else if ( preg_match("/\.(csv)$/",$filename) ) { $mimetype = "text/csv";
} else if ( preg_match("/\.(htm)$/",$filename) ) { $mimetype = "text/htm";
} else if ( preg_match("/\.(html)$/",$filename) ) { $mimetype = "text/html";
} else if ( preg_match("/\.(doc)$/",$filename) ) { $mimetype = "application/vnd.ms-word";
} else if ( preg_match("/\.(xls)$/",$filename) ) { $mimetype = "application/vnd.ms-excel";
} else { $mimetype = "text/txt"; }


function sendmsg($to, $subject, $msgtext, $from, $file, $type)
{

// $fp = fopen($file,"r");
// $fcontent = fread($fp ,filesize($file));
// fclose($fp);
// $content = chunk_split(base64_encode($fcontent));
$sep = strtoupper(md5(uniqid(time())));
$name = basename($file);
$header = "From: $from\nReply-To: $from\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=$sep\n";
$body .= "--$sep\n";
$body .= "Content-Type: text/plain\n";
$body .= "Content-Transfer-Encoding: 8bit\n\n";
$body .= "$msgtext\n";
// $body .= "--$sep\n";
// $body .= "Content-Type: $type; name=\"$file\"\n";
// $body .= "Content-Transfer-Encoding: base64\n";
// $body .= "Content-Disposition: attachment; filename=\"$file\"\n";
// $body .= "$content\n";
$body .= "--$sep--";
if (mail($to, $subject, $body, $header)) {
return true;
} else {
return false;
}
}

sleep(0.25);
sendmsg($recipient, $subject, $contact_info, $froms_, $target_path, $mimetype);

[/PHP]

Yes the attachment code is now commented because I have it working to send emails only with a link to the document instead of an attachment. But All i did was comment out instead of rewrite code. BIGUPS and appreciation!
May 25 '07 #1
3 2000
Motoma
3,237 Expert 2GB
I think you will need another newline before the content.
May 25 '07 #2
I think you will need another newline before the content.
Jeezz, you are correct. Lesson learned! thnx
May 25 '07 #3
Motoma
3,237 Expert 2GB
Jeezz, you are correct. Lesson learned! thnx
No problem. Welcome to The Scripts.
May 26 '07 #4

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

Similar topics

4
by: Paul Schmidt | last post by:
Dear list: I am new to python, and I am trying to figure out the short answer on something. I want to open a POP3 mailbox, read the enclosed mail using the POP3 module, , and then process it...
3
by: LutherRevisited | last post by:
Is there a way I can put a message together without having to download any attachments there may be at the same time. I'm not having any problems dealing with attachments, but the way I'm doing...
5
by: morphex | last post by:
Hi, I have an email that's in the utf-8 encoding, and I'm getting this error message when I try to send it using smtplib: * Module smtplib, line 688, in sendmail * Module smtplib, line 485,...
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. ...
4
by: Russell Bungay | last post by:
Hello all, I have written a short function, based on a recipe in the Python Cookbook, that sends an e-mail. The function takes arguments that define who the e-mail is to, from, the subject, the...
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...
10
by: OdAwG | last post by:
Hello All, Is it possible to send an email from Access? I found a Microsoft article on how to do this but I keep getting an error "RUNTIME ERROR 438" -- Object doesn't support this property or...
10
by: Walshi | last post by:
Hi all, I'm a relative newby to access and VBA etc. My forms and tables etc are working great and saving lots of time...However... I have two databases with the exact same table format. I want...
2
by: oyster | last post by:
I find that the existing email moudle is some hard for me to understand, especially the part of how to set the CC, BCC and attach the files. Is there any more easy one like this p-code? import...
1
by: budyerr | last post by:
All, I am trying to build a email submission form using asp.net. I currently have a web form page that will upload to my webhosting server, attach to email then delete the file after sending. ...
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
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
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.