0

Hi,

I am uploading a file(text,doc) in php.its working fine.
I want to send this uploaded file as attached file to admin.my mail function is working fine.but i don,t know how to attach that uploaded file.
need help.

Thanks

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by makman99
0

Hi Jacob, the easiest way would be to use some mailing library like XPertMailer http://www.xpertmailer.com/. It would take care of all the boring stuff related to sending attachments or html e-mails or validating e-mail addresses, or even protecting yourself from e-mail injection attack.

If you however, insist on implementing it yourself, here's a good tutorial:
http://www.webcheatsheet.com/PHP/send_email_text_html_attachment.php
It's the #1 hit in Google when you search for "send attachment php".

Petr

0

Can anyone have code to send attached file in php.
Thanks

0

If you can't click the link provided and scroll down, here's the code it gives on emailing attachments(stripped of comments):

<?php
$to = 'youraddress@example.com';
$subject = 'Test email with attachment';
$random_hash = md5(date('r', time()));
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));
ob_start();
?>
--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!!!
This is simple text email message.

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>

--PHP-alt-<?php echo $random_hash; ?>--

--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: application/zip; name="attachment.zip" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 

<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--

<?php
$message = ob_get_clean();
$mail_sent = @mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.