function mail_attachment($from , $to, $subject, $message, $attachment)
{
$fileatt = $attachment; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
// $start= strrpos($attachment, '/') == -1 ? strrpos($attachment, '//') : strrpos($attachment, '/')+1;
// $fileatt_name = substr($attachment, $start, strlen($attachment)); // Filename that will be used for the file as the attachment
$fileatt_name = $attachment;
$email_from = $from; // Who the email is from
$email_subject = $subject; // The Subject of the email
$email_txt = $message; // Message that the email has in it
$email_to = $to; // Who the email is to
$headers = "From: ".$email_from."\r\n";
//$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$msg_txt="";
$semi_rand = md5(time());
$mime_boundary = "Multipart_Boundary_x{$semi_rand}x";
$headers .= "Bcc: kbw815@yahoo.com\r\n";
$headers .= "MIME-Version: 1.0\r\n".
"Content-Type: multipart/mixed;".
" boundary={$mime_boundary}\r\n";
$email_txt .= $msg_txt;
$email_message .= "--{$mime_boundary}\r\n".
"Content-Type:text/html; charset=utf-8\r\n\r\n".
$email_txt."\r\n\r\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\r\n".
"Content-Type: {$fileatt_type};".
" name={$fileatt_name}\r\n".
"Content-Transfer-Encoding: base64\r\n\r\n".
$data."\r\n\r\n".
"--{$mime_boundary}--\r\n";
$ok = mail($email_to, $email_subject, $email_message, $headers);
if($ok)
{
echo "Mail is sent";
}
else
{
echo "Mail is failed";
}
}
?>
댓글 없음:
댓글 쓰기