Your Open Source

 
Related Posts

How to send mails with attachment in php

How to send mails with attachment in php :- You can send the email with attachment using PHP mail() function.

  • hits 14881
  • datetime Jul 08 08 04:23:20
  • author Sekar
  • rating

PHP Mail
The php mail with attachement code as follows
<?php
$random_hash = md5(date('r', time()));

$subject = "Attachement Mail in PHP";
$message = "You can attach the files with e-mail in PHP mail function';

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

/* additional headers */
$headers .= "To: phpkit <admin@phpkit.in>\r\n";
$headers .= "From: Sam <sam@phpkit.in>\r\n";
$attachment = chunk_split(base64_encode(file_get_contents('attachment_files.zip')));
$headers . ='Content-Type: multipart/alternative; boundary="==Multipart_Boundary_x{'.$random_hash.')';
$mail_content .= "This is a multi-part message in MIME format.\n\n" .
                "--Multipart_Boundary_x{{$random_hash})\n" .
                "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
               "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
               

"--Multipart_Boundary_x{{$random_hash})\n
Content-Type: application/zip; name=\"attachment.zip\"
Content-Transfer-Encoding: base64 \n\n
Content-Disposition: attachment \n\n ".$attachment."\n\n".
"--Multipart_Boundary_x{{$random_hash})--\n";

/* and now mail it */
mail("admin@phpkit.in", $subject, $mail_content, $headers);

?>

Rating : 12345
Tags :- PHP

Answers

narinder
Aug 14 10 12:23:04
hello

vijay
Dec 01 09 09:26:44
<?php
$random_hash = md5(date('r', time()));

$subject = "Attachement Mail in PHP";
$message = "You can attach the files with e-mail in PHP mail function';

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

/* additional headers */
$headers .= "To: phpkit <admin@phpkit.in>\r\n";
$headers .= "From: Sam <sam@phpkit.in>\r\n";
$attachment = chunk_split(base64_encode(file_get_contents('attachment_files.zip')));
$headers . ='Content-Type: multipart/alternative; boundary="==Multipart_Boundary_x{'.$random_hash.')';
$mail_content .= "This is a multi-part message in MIME format.\n\n" .
                "--Multipart_Boundary_x{{$random_hash})\n" .
                "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
               "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
               

"--Multipart_Boundary_x{{$random_hash})\n
Content-Type: application/zip; name=\"attachment.zip\"
Content-Transfer-Encoding: base64 \n\n
Content-Disposition: attachment \n\n ".$attachment."\n\n".
"--Multipart_Boundary_x{{$random_hash})--\n";

/* and now mail it */
mail("admin@phpkit.in", $subject, $mail_content, $headers);

?>

Your Name:
Your Answers :
<> is a code tag
Preview
Enter the verification code: