<?php
//Set Email Subject
$subject = $_POST['sub'];
$message_email=$_POST['message'];
$message_email.='<br><br><br>'.$data;
//define the from \ reply to headers
$headers = "From: darshakkumarshah@mkics.in\r\nReply-To: darshakkumarshah@mkics.in";
//create a unique boundary string to delimit different parts of the email (plain text, html, file attachment)
$random_hash = md5(date('r', time()));
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks for sending
$attachment = chunk_split(base64_encode(file_get_contents($file_nm)));
//define the body of the message.
$message = "--PHP-mixed-$random_hash\r\n"
."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
$message .= "--PHP-alt-$random_hash\r\n"
."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n";
//Insert the plain text message.
$message .= strip_tags($data);
$message .= "\r\n\r\n--PHP-alt-$random_hash\r\n"
."Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n";
//Insert the html message.
$message .= $message_email;
$message .="\r\n\r\n--PHP-alt-$random_hash--\r\n\r\n";
//include attachment
if(isset($_POST['checkbox']))
{
$message .= "--PHP-mixed-$random_hash\r\n"
."Content-Type: application/pdf; name=".$file_nm."\r\n"
."Content-Transfer-Encoding: base64\r\n"
."Content-Disposition: attachment\r\n\r\n";
$message .= $attachment;
$message .= "/r/n--PHP-mixed-$random_hash--";
}
//send the email
$mail = mail( $to, $subject , $message, $headers );
?>
No comments:
Post a Comment