【发布时间】:2012-12-28 09:08:03
【问题描述】:
正在发送带有文件附件的邮件,但无法打开它。
这是什么问题,请解决。
<?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";
?>
【问题讨论】:
-
我建议你使用PHPmailer phpmailer.worxware.com
-
我强烈推荐the Mail module of the zeta components 发送带有附件的邮件。会让你的生活轻松很多。
-
@AL-Kateb 你想说什么?我在哪里使用 PHPmailer phpmailer.worxware.com?
-
我正在使用此代码并且正在发送邮件但文件未打开。
标签: php