attach files in PHP

lightingever's picture

They have: 39 posts

Joined: Sep 2010

Hi all,

Please tell me the procedure of sending attached files in PHP. If it is possible, please, provide me with ready code examples.plz help me. Thank you in advance.

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

My main recommendation would be to use PhpMailer, as a lot of the work including setting up messages, validating e-mail addresses, etc, are set up for you. We use this on just about all out client's sites for sending anything over a quick simple message.

The main site is:
http://phpmailer.worxware.com/index.php?pg=phpmailer

However it can be a little misleading to get the actual download. When you click on the link to download it, it takes you to a sourceforge page: (this is for PHP5/6)
http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/

Ignore the green button to Download Now (as the file isn't in that download) and below that, in the "Browse Files for PHPMailer", expand the 2nd one down, "PHPMailer v5.1" and grab which ever compression type you want.

The main file you need on your server is the class.phpmailer.php, then to get you up and running, check examples/test_mail_basic.php or examples/test_sendmail_basic.php. The samples demonstrate the basics pretty well!

-Greg

He has: 13 posts

Joined: May 2010

you can use the following code to sent text files attachments in php

<?php
$to
= '[email protected]';
$subject = 'Test email';
$message = "Hello World!\n\nThis is my first mail.";
$headers = "From: [email protected]\r\nReply-To: [email protected]";
$mail_sent = @mail( $to, $subject, $message, $headers );
echo
$mail_sent ? "Mail sent" : "Mail failed";
?>

They have: 5 posts

Joined: Feb 2010

Search for upload code in php . You will find tons of code

They have: 2 posts

Joined: Dec 2010

search for upload code in php . You will find tons of code

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.