send email attachments (any format)
Posted: Fri Nov 11, 2011 12:07 am
This is the code. I don’t get any error. But email is not sent. can anybody help?
Also, I need to send any type of file (mp3/pdf/txt/wma/doc)
Also, I need to send any type of file (mp3/pdf/txt/wma/doc)
Code: Select all
<?php
session_start();
$msg="";
if (isset($_POST['Submit1']))
{
$scname=$_POST['scname'];
$file_name=$_FILES["file"]["name"];
$splt = explode(".",$file_name);
$fpart=$_POST["scname"].".".$splt[1];
if(file_exists("Events/".$fpart))
{
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],"Events/".$fpart);
}
$to="xxx@xxx.com";
$from="xxx@xxx.com";
$subject="Event Registration – For approval";
$message="Event Registration Request…..";
$random_hash = md5(date('r', time()));
$headers = "From: xxx@xx.com\r\nReply-To: xxx@xxx.com";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents("Events/".$fpart)));
$output = "
–PHP-mixed-$random_hash;
Content-Type: multipart/alternative; boundary='PHP-alt-$random_hash'
–PHP-alt-$random_hash
Content-Type: text/plain; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
Hello World!
This is the simple text version of the email message.
–PHP-alt-$random_hash
Content-Type: text/html; charset='iso-8859-1'
Content-Transfer-Encoding: 7bit
Hello World!
This is the HTML version of the email message.
–PHP-alt-$random_hash–
–PHP-mixed-$random_hash
Content-Type: application/octet-stream; \”$fpart\”\n
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
–PHP-mixed-$random_hash–”;
echo @mail($to, $subject, $output, $headers);
}
?>