Solved

Sending an email attachment

Posted on 2004-09-07
6
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 25

Expert Comment

by:Marcus Bointon
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:
Marcus Bointon 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 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