Solved

Sending an email attachment

Posted on 2004-09-07
6
179 Views
Last Modified: 2006-11-17
Hi,

For my website, I want to write a feature that will allow me to send through an email attachment some of my hosted files to users.  However, once I have opened and read the file into a variable, i cant seem to actually make the attachment work :(

Can someone help me out?

Cheers

MrBarby
0
Comment
Question by:MrBarby
  • 2
  • 2
6 Comments
 
LVL 25

Expert Comment

by:Squinky
ID: 11996924
Don't bother using mail(). Download PHPMailer from phpmailer.sourceforge.net, upload it to your web area and call it with a script like the ones here:

http://phpmailer.sourceforge.net/tutorial.html#3
http://phpmailer.sourceforge.net/extending.html

You don't need to load the file before sending it, just point PHPMailer at the file and it will grab it for you.
0
 

Author Comment

by:MrBarby
ID: 11997664
OK, thanks, I'll give that a go :)
0
 

Author Comment

by:MrBarby
ID: 11998774
Hmm... I just tested this and it didn't seem to work.  Please note that I'm trying to download files that may not necessarily be from the same server, i.e. an http/ftp link.  Should this class still work with that?
0
 
LVL 25

Accepted Solution

by:
Squinky earned 250 total points
ID: 11999996
Well, you could do something like:

$mail->AddStringAttachment(file_get_contents($url), 'somefile.txt');

but I wouldn't advise that as it has no scope for error control, and remote links are prone to error. It is worth separating the two parts of the process. Instead, use file_get_contents to grab the remote file contents and save it locally, then pass the path to PHPMailer using a normal attachment:

$mail->AddAttachment($localpath);
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now