phpのメール機能を使ってpdfを添付したメールを送ろうとしています。メールで他のものを受け取っていますが、添付ファイルのサイズはゼロキロバイトです。誰かが私のコードを見て、ここで何が間違っているかを提案できますか?
ありがとう!以下はコードです:
public static function sendMailWithAttachment($to, $from, $from_name, $subject, $msg,$attachmentName, $attachmentPath){
// Setting a timezone, mail() uses this.
//date_default_timezone_set('America/New_York');
$semi_rand = md5(time());
$data = chunk_split(base64_encode($data));
$fileatt_type = "application/pdf"; // File Type
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// set header ........................
$headers = "From: ".$from;
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// set email message......................
//$email_message = "Thanks for visiting ";
//$email_message .= "Thanks for visiting.<br>";// Message that the email has in it
$email_message=$msg;
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$attachmentPath}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$attachmentName}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";
$sent = @mail($to, $subject, $email_message, $headers);
if($sent) {
echo "Your email attachment send successfully.";
} else {
die("Sorry but the email could not be sent. Please try again!");
}
}