【发布时间】:2017-06-23 18:01:25
【问题描述】:
我有发送带有附件的电子邮件的 PHP 代码,但我想要将全名、联系电话等所有数据放入表格中。我尝试使用<table>,但电子邮件仍然是纯文本。有人可以帮我制作吗?
这是我的 php 代码:
<?php
$cname = $_POST['Name'];
$cnumber = $_POST['Tel'];
$cemail = $_POST['emailadd'];
$cmess = $_POST['contactmess'];
$index = 'index.php';
move_uploaded_file($_FILES["attachment"]["tmp_name"] , "/files/upload/" . $_FILES["attachment"]["name"]);
$to = 'peace@gmail.com';
$subject = 'Careers Inquiry';
$random_hash = md5(date('r', time()));
$headers = "From: ". $cemail ."\r\nReply-To:". $cemail;
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$headers .= "Content-Type: text/html; charset='iso-8859-1'";
$attachment = chunk_split(base64_encode(file_get_contents("/files/upload/" .$_FILES["attachment"]["name"])));
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
--PHP-alt-`<?php echo $random_hash; ?>`
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<html>
<body>
<table>
<tr><td>Name: </td><td><?php echo $cname; ?></td></tr>
<tr><td>Contact Number: </td><td><?php echo $cnumber; ?></td></tr>
<tr><td>Email Address: </td><td><?php echo $cemail; ?></td></tr>
<tr><td>Message: </td><td><?php echo $cmess; ?></td></tr>
</table>
</body>
</html>
--PHP-alt-`<?php echo $random_hash; ?>`--
--PHP-mixed-`<?php echo $random_hash; ?>`
Content-Type: application/octet-stream; name="`<?php echo $_FILES["attachment"]["name"];?>`"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
`<?php echo $attachment; ?>`
--PHP-mixed-`<?php echo $random_hash; ?>`--
<?php
$message = ob_get_clean();
$mail_sent = @mail( $to, $subject, $message, $headers );
unlink('/files/upload/' . $_FILES["attachment"]["name"]);
echo $mail_sent ? header('Location: '. $index): '<script type="text/javascript"> alert("Sorry, service temporary unavailable."); </script>';
?>
【问题讨论】:
标签: php html html-table html-email email-attachments