473,651 Members | 3,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP 4.1.1 and Email Attachments

3 New Member
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(bas e64_encode($fil ename))[/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 = "applicatio n/vnd.ms-word";
} else if ( preg_match("/\.(xls)$/",$filename ) ) { $mimetype = "applicatio n/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(bas e64_encode($fco ntent));
$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=\"$fil e\"\n";
// $body .= "$content\n ";
$body .= "--$sep--";
if (mail($to, $subject, $body, $header)) {
return true;
} else {
return false;
}
}

sleep(0.25);
sendmsg($recipi ent, $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 2011
Motoma
3,237 Recognized Expert Specialist
I think you will need another newline before the content.
May 25 '07 #2
sylence
3 New Member
I think you will need another newline before the content.
Jeezz, you are correct. Lesson learned! thnx
May 25 '07 #3
Motoma
3,237 Recognized Expert Specialist
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
3728
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 using the email module. Environment Python 2.3.4, Mandrake Linux 9.0 patched up the wazoo...
3
3139
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 things makes me download the complete message first, attachements and all: mail = for j in M.retr(i): mail.append(j.rstrip()) inMail = email.message_from_string('\r\n'.join(mail)) I don't have a real problem per se with this, it's just that I...
5
12677
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, in data * Module smtplib, line 312, in send * Module socket, line 1, in sendall
5
15928
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. Public Function PrintPDFemail2() ' This will create the PDF if the report is setup for it DoCmd.OpenReport "rptJobItemStat", acViewNormal
4
1936
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 body and an optional list of attachments. The function works also perfectly, bar one slight problem. If you attempt to send an e-mail with just a body and no attachments, the receiving client still thinks that there is an attachment (so far...
1
2881
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 tables and emails the reports as HTML format in the body, I then need to have this same process go out to my C:\ drive and pick up a couple files and add it to the same email as attachments. If someone could please give me a sample code that would...
10
4963
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 method. Listed below is the article from microsoft How to use a recordset to send Outlook e-mail to multiple recipients in Microsoft Access http://support.microsoft.com/?id=318881
10
2186
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 db1 to be used to input data by a remote operator, when she is ready I want her to be able to click a control button to email her new data to db2. This new data will be added to the table in db2 ready for further processing.
2
2645
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 easyemail smtpserver=easyemail.server('something') smtpserver.login('usr@gmail.com', pwd) newletter=smtpsever.letter(smtpserver) newletter.sendto= newletter.sendcc=
1
3867
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. This works great with one attachment. I am requiring that a file be attach before submitting. Now I am trying to add the ability to add multiple attachments and I am able to create this however, it will error out if all of the attachment is not...
0
8361
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8807
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8701
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8584
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7299
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.