正在发送带有文件附件的邮件,但无法打开它。
有什么问题请解决这个问题。
<?php
$file_name=$_FILES['Resume']['name'];
$file_size=$_FILES['Resume']['size'];
$file_temp=$_FILES['Resume']['tmp_name'];
$to = 'renu_activa@yahoo.co.in';
$subject = 'Test email with attachment';
$from=$_POST['First'];
$random_hash = md5(date('r', time()));
$headers = "From: $from\r\nReply-To: $from";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$data = chunk_split(base64_encode(file_get_contents("$file_temp")));
ob_start();
?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hello World!!!
This is simple text email message.
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<h2>Hello World!</h2>
<p>This is something with <b>HTML</b> formatting.</p>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: $file_type; name=$file_name
Content-Transfer-Encoding: base64
Content-Disposition: attachment
<?php echo $data; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>