Solved

Sending an email attachment

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

770 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