user93796
user93796

Reputation: 18399

Send email with attachments in PHP?

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

Upvotes: 2

Views: 1525

Answers (4)

Pons
Pons

Reputation: 1776

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.

Upvotes: -1

Zed
Zed

Reputation: 57678

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");

Upvotes: 3

VinkoCM
VinkoCM

Reputation: 337

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.

Upvotes: 0

chaos
chaos

Reputation: 124365

I recommend using PHPMailer.

Upvotes: 6

Related Questions