单击提交按钮后,浏览器将转到www。****。com / contact.php,页面为空白。电子邮件也未送达。这是我第一次处理php。我错过了什么?
以下是表格:
<form class="comment-form" action="contact.php" method="POST">
<p class="comment-notes">Your email address will not be published. All fields are required.</p>
<p class="comment-form-email">
<label for="author">Name</label>
<span class="required">*</span>
<input id="author" type="text" class="input-text" name="name">
</p>
<p class="comment-form-author">
<label for="email">Email</label>
<span class="required">*</span>
<input id="email" type="text" class="input-text" name="email">
</p>
<p class="comment-form-url">
<label for="subject">Subject</label>
<span class="required">*</span>
<input id="subject" type="text" class="input-text" name="subject">
</p>
<p class="comment-form-comment">
<label for="message">Message</label>
<textarea name="message" id="message" cols="45" rows="10" class="input-text"></textarea>
</p>
<p class="form-submit">
<input class="btn btn-md btn-default" name="submit" type="submit" id="button" value="Send"><input type="reset" value="Clear">
</p>
</form>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$formcontent = "From: $name\n Message: $message";
$recipient = "me@example.com";
$subject = "$subject";
$mailheader = "From: $email \r\n";
error_reporting(E_ALL);
ini_set(display_errors, 1);
mail($recipient, $subject, $formcontent, $mailheader) or die ("Error!");
echo "Thank You! We will respond to your inquiry as soon as possible"; " -"<a href='contact.html' style='text-decoration:none;color:#ff0099;'> "Return Home"</a>;
?>
答案 0 :(得分:2)
看起来这个表单正在发布给自己?如果是这种情况,我认为您应该使用
<form class="comment-form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
htmlspecialchars()是安全的事情。有助于防止一些黑客攻击。
答案 1 :(得分:1)
看起来您的PHP没有被正确调用,因为它没有被提交按钮触发。按下提交按钮时执行以下代码。
if(isset($_POST['submit']
{
// put your PHP code here, this executes when submit is...submitted
}
给它一个镜头,它应该帮助你一些。
<?php
error_reporting(E_ALL);
ini_set(display_errors, 1);
if(isset($_POST['submit']))
{
//Gather the POST info and set them to variables
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// Setup the message and define who will be emailed the info
$formcontent = "From: $name\n Message: $message";
$recipient = "pbentley07@gmail.com";
$headers = 'From:' . $email;
mail("$recipient", $subject, $formcontent, $headers) or die ("Error!");
echo "Thank You! We will respond to your inquiry as soon as possible! - <a href='contact.html' style='text-decoration:none;color:#ff0099;'>Return Home</a>";
}
?>
<form class="comment-form" action="contact.php" method="POST">
<p class="comment-notes">Your email address will not be published. All fields are required.</p>
<p class="comment-form-email">
<label for="author">Name</label>
<span class="required">*</span>
<input id="author" type="text" class="input-text" name="name">
</p>
<p class="comment-form-author">
<label for="email">Email</label>
<span class="required">*</span>
<input id="email" type="text" class="input-text" name="email">
</p>
<p class="comment-form-url">
<label for="subject">Subject</label>
<span class="required">*</span>
<input id="subject" type="text" class="input-text" name="subject">
</p>
<p class="comment-form-comment">
<label for="message">Message</label>
<textarea name="message" id="message" cols="45" rows="10" class="input-text"></textarea>
</p>
<p class="form-submit">
<input class="btn btn-md btn-default" name="submit" type="submit" id="button" value="Send"><input type="reset" value="Clear">
</p>
</form>
答案 2 :(得分:0)
您能否确认您在此处发布的页面+代码
是contact.php
档案吗?
首先尝试修复您的PHP代码,这一行:
echo "Thank You! We will respond to your inquiry as soon as possible"; " -"<a href='contact.html' style='text-decoration:none;color:#ff0099;'> "Return Home"</a>;
必须是:
echo "Thank You! We will respond to your inquiry as soon as possible";
?>
<a href="contact.html" style="text-decoration:none;color:#ff0099;">Return Home</a>
<?php
答案 3 :(得分:0)
echo "Thank You! We will respond to your inquiry as soon as possible - <a href='contact.html' style='text-decoration:none;color:#ff0099;'>\"Return Home\"</a>";
答案 4 :(得分:0)
你有一些严重的错误&#34;在你的PHP中:
$message
未定义
$subject
未定义
它是ini_set('display_errors', 1);
,而不是ini_set(display_errors, 1);
您的echo
行无效,请删除其他HTML部分
你的最终代码应该是这样的:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$formcontent = "From: $name\n Message: $message";
$recipient = "me@example.com";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die ("Error!");
echo "Thank You! We will respond to your inquiry as soon as possible";
?>
<a href='contact.html' style='text-decoration:none;color:#ff0099;'> "Return Home"</a>
您可能还想阅读表单验证