我正在尝试将这个PHP代码集成到我的联系表单中,所有html输入都很好,php脚本中一定有错误,这里是代码:
<?php
$to = 'test@email.com;
$subject = 'New Website Message';
$headers = 'From: (Website Form) <POST['email']>' . "\r\n" . 'Content-type: text/html; charset=utf-8';
$message = '
<html>
<head>
<title>You have received a new message!</title>
</head>
<body>
<h3>Name: <span style="font-weight: normal;">' . $_POST['name'] . '</span></h3>
<h3>Email: <span style="font-weight: normal;">' . $_POST['email'] . '</span></h3>
<div>
<h3 style="margin-bottom: 5px;">Message:</h3>
<div>' . $_POST['message'] . '</div>
</div>
</body>
</html>';
if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['message'])) {
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
mail($to, $subject, $message, $headers) or die('<span style="color: red;">Error sending Mail</span>');
echo '<span class="send-true" style="color: #00dd63;">Your email was sent!</span>';
}
} else {
echo '<span style="color: red;">All fields must be filled!</span>';
}
?>
答案 0 :(得分:2)
好像你有一个语法错误的人。 试试这个:
<?php
$to = 'test@email.com';
$subject = 'New Website Message';
$headers = 'From: (Website Form) <$_POST['email']>' . "\r\n" . 'Content-type: text/html; charset=utf-8';
$message = '
<html>
<head>
<title>You have received a new message!</title>
</head>
<body>
<h3>Name: <span style="font-weight: normal;">' . $_POST['name'] . '</span></h3>
<h3>Email: <span style="font-weight: normal;">' . $_POST['email'] . '</span></h3>
<div>
<h3 style="margin-bottom: 5px;">Message:</h3>
<div>' . $_POST['message'] . '</div>
</div>
</body>
</html>';
if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['message'])) {
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
mail($to, $subject, $message, $headers) or die('<span style="color: red;">Error sending Mail</span>');
echo '<span class="send-true" style="color: #00dd63;">Your email was sent!</span>';
}
} else {
echo '<span style="color: red;">All fields must be filled!</span>';
}
?>