tags:

views:

205

answers:

4

How can I send emails with attachments with a PHP script?

+5  A: 

I recommend using PHPMailer.

chaos
A: 

I would recommend that you take a look at some of the PHP PEAR packages designed for sending emails. I know that some PHP programmers like reinventing the wheel, but take a look at the packages. They are easy to use and implement and you should have no problem finding help.

Here is a link: http://pear.php.net/package/Mail

You may want to use the go-pear.php script to install the packages. It will make life a lot easier.

VinkoCM
+2  A: 

Use SwiftMailer.

$message = new Swift_Message("My subject");

$message->attach(new Swift_Message_Part("Attached txt file"));
$message->attach(new Swift_Message_Attachment(new Swift_File("filename.txt"), "filename.txt", "text/txt"));

$swift->send($message, "email@host", "myemail@host");
Zed
A: 

If you simply want a php function, you can use this mail_file function: http://www.barattalo.it/2010/01/10/sending-emails-with-attachment-and-html-with-php/

To send files you have to base64 encode the file and use the "header" parameter of the php mail function.

Hope this will help.

Pons