我有一个可用的邮件脚本,但是我想让它看起来更好用一些HTML。我添加了HTML,但$_POST
数据丢失了,它只是显示[contents]
。添加的HTML工作原因是[contents]
在html中。显示[内容]而不是实际内容的邮件
这是邮件脚本:
<?php
session_cache_limiter('nocache');
header('Expires: ' . gmdate('r', 0));
header('Content-type: application/json');
// Enter your email address
$to = '[email protected]';
$subject = 'Aanvraag op website door '.$_POST['name'].'';
if($to) {
$name = $_POST['name'];
$email = $_POST['email'];
$fields = array(
0 => array(
'text' => 'Naam',
'val' => $_POST['name']
),
1 => array(
'text' => 'Email adres',
'val' => $_POST['email']
),
2 => array(
'text' => 'Adres',
'val' => $_POST['adres']
),
3 => array(
'text' => 'Afleveradres',
'val' => $_POST['afleveradres']
),
4 => array(
'text' => 'Postcode',
'val' => $_POST['postcode']
),
5 => array(
'text' => 'Plaats',
'val' => $_POST['plaats']
),
6 => array(
'text' => 'Tweede plaats',
'val' => $_POST['plaats2']
),
7 => array(
'text' => 'Telefoonnummer',
'val' => $_POST['telefoonnr']
),
8 => array(
'text' => 'Mobiel nummer',
'val' => $_POST['mobielnr']
),
9 => array(
'text' => 'Type Raam',
'val' => implode(',', $_POST['checkbox'])
),
10 => array(
'text' => 'Werkzaamheden',
'val' => implode(',', $_POST['werkzaamheden'])
),
11 => array(
'text' => 'Contactpersoon',
'val' => $_POST['contactpersoon']
),
12 => array(
'text' => 'Bericht',
'val' => $_POST['message']
)
);
$message = "";
foreach($fields as $field) {
$message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
}
$message = '
<table border="0" width="100%" cellspacing="0" cellpadding="0" style="font-family:calibri;color: #5C5C5C; font-size:10pt;line-height:22px;">
<tr>
<td width="160" valign="top" style="font-family:calibri;padding-left:10px;padding-top:20px;">
[contents]
</td>
</tr>
<tr>
<td width="160" valign="top" style="font-family:calibri;padding-left:10px;padding-top:20px;">
<br><br>Met vriendelijke groet,<br><br>
Helpdesk<br>
<b>website</b><br>
<p></p>
</td>
</tr>
</table>
<table height="120" border="0" width="100%" cellspacing="0" cellpadding="0" style="font-family:calibri;color: #5C5C5C; font-size:10pt;line-height:22px;">
<tr>
<td width="250" valign="top" style="font-family:calibri;padding-left:10px;padding-top:20px;border-top: 1px #000000 dotted; border-bottom: 1px #000000 dotted;">
E:
<a href="mailto:[email protected]" style="font-family:calibri;color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;">[email protected]</a><br>
T:
<a href="tel:0615086609" style="font-family:calibri;color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;">0615086609</a><br>
W:
<a href="http://website.nl" style="font-family:calibri;color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;" target="_blank">www.website.nl</a><br>
</td>
<td align="right" style="font-family:calibri;padding-right:10px;padding-top:5px;border-top: 1px #000000 dotted; border-bottom: 1px #000000 dotted;">
<a href="http://website.nl/" target="_blank" title="Ga naar de website">
<img src="http://www.website.nl/_extern/website/images/logo.png" alt="Ga naar de website" style="font-family:calibri;text-align:right;margin:0px;padding:10px 0 10px 0;" border="0" width="232">
</a>
</td>
</tr>
<tr>
<td colspan="2" style="font-family:calibri;color:#a3a3a3;font-size:11px;margin-top:6px;line-height:14px;">
<br>Dit e-mailbericht is uitsluitend bestemd voor de geadresseerde. Als dit bericht niet voor u bestemd is, wordt u vriendelijk verzocht dit aan de afzender te melden. website staat door de elektronische verzending van dit bericht niet in voor de juiste en volledige overbrenging van de inhoud, noch voor tijdige ontvangst daarvan. Voor informatie over website raadpleegt u <a href="http://website.nl" style="font-family:calibri;color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;" target="_BLANK">website</a>.<br><br>
</td>
</tr>
</table>';
$headers = '';
$headers .= 'From: ' . $name . ' <' . $email . '>' . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
if (mail($to, $subject, $message, $headers)){
$arrResult = array ('response'=>'success');
} else{
$arrResult = array ('response'=>'error');
}
echo json_encode($arrResult);
} else {
$arrResult = array ('response'=>'error');
echo json_encode($arrResult);
}
?>
有谁知道我做错了吗? HTML正在工作,但未显示来自foreach
的数据。
你有[内容]字符串,你期望发生什么? – Nick
是的,我忘了将它添加到原始文章中,但我现在编辑它。 – twan