我根据回答更新了下面的代码PHP 500错误联系表格?
完全披露我不知道PHP。我需要一个联系表单,并且我明白下面的代码足以让您感觉很舒服。但是,当我尝试提交联系表格时,我收到一个错误: POST http://(myurlhere)/contact_form.php 500(内部服务器错误)
我非常感谢任何见解。下面是代码:
HTML
<form id="form">
<p id="returnmessage"></p>
<input type="text" id="name" placeholder="Name"/>
<input type="text" id="email" placeholder="Email"/>
<textarea id="message" placeholder="Your Message Here"></textarea>
</form>
<a id="submit">Send</a>
PHP
<?php
// Fetching Values from URL.
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$email = filter_var($email, FILTER_SANITIZE_EMAIL); // Sanitizing E-mail.
// After sanitization Validation is performed
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
// if (!preg_match("/^[0-9]{10}$/", $contact)) {
// echo "<span>* Please Fill Valid Contact No. *</span>";
} else {
$subject = $name;
// To send HTML mail, the Content-type header must be set.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:' . $email. "\r\n"; // Sender's Email
$headers .= 'Cc:' . $email. "\r\n"; // Carbon copy to Sender
$template = '<div style="padding:50px; color:white;">Hello ' . $name . ',<br/>'
. '<br/>I will be in touch soon.<br/><br/>'
. 'Name:' . $name . '<br/>'
. 'Email:' . $email . '<br/>'
. 'Message:' . $message . '<br/><br/>'
. 'This is a Contact Confirmation mail.'
. '<br/>'
. 'We Will contact You as soon as possible .</div>';
$sendmessage = "<div style=\"background-color:#7E7E7E; color:white;\">" . $template . "</div>";
// Message lines should not exceed 70 characters (PHP rule), so wrap it.
$sendmessage = wordwrap($sendmessage, 70);
// Send mail by PHP Mail Function.
mail("[email protected]", $subject, $sendmessage, $headers);
echo "I will be in touch soon.";
}
} else {
echo "<span>* invalid email *</span>";
}
?>
新代码 - 它发出的消息,但没有包括在喜欢它的电子邮件的姓名,电子邮件或消息应该。
新的HTML
<form id="form" method="post" action="">
<p id="returnmessage"></p>
<input type="text" id="name" name="name" placeholder="Name"/>
<input type="text" id="email" name="email" placeholder="Email"/>
<textarea id="message" name="message" placeholder="Message"></textarea>
<button id="submit" id="submit">Send</button>
</form>
新PHP
<?php
// Fetching Values from URL.
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$email = filter_var($email, FILTER_SANITIZE_EMAIL); // Sanitizing E-mail.
// After sanitization Validation is performed
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
// if (!preg_match("/^[0-9]{10}$/", $contact)) {
// echo "<span>* Please Fill Valid Contact No. *</span>";
} else {
$subject = $name;
// To send HTML mail, the Content-type header must be set.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:' . $email. "\r\n"; // Sender's Email
$headers .= 'Cc:' . $email. "\r\n"; // Carbon copy to Sender
$template = '<div style="padding:50px; color:white;">Hello ' . $name . ',<br/>'
. '<br/>I will be in touch soon.<br/><br/>'
. 'Name:' . $name . '<br/>'
. 'Email:' . $email . '<br/>'
. 'Message:' . $message . '<br/><br/>'
. 'This is a Contact Confirmation mail.'
. '<br/>'
. 'We Will contact You as soon as possible .</div>';
$sendmessage = "<div style=\"background-color:#7E7E7E; color:white;\">" . $template . "</div>";
// Message lines should not exceed 70 characters (PHP rule), so wrap it.
$sendmessage = wordwrap($sendmessage, 70);
// Send mail by PHP Mail Function.
mail("[email protected]", $subject, $sendmessage, $headers);
echo "I will be in touch soon.";
}
?>
有你提到的代码没有动作。 '