Solved

Sending an email attachment

Posted on 2004-09-07
6
189 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
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.

751 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