希望你能提供帮助,我正在尝试为我的网站点击一个联系表格,这是HTML格式,用CSS格式化,以及用PHP发送的电子邮件。
问题一:当通过联系表单提交邮件时,它不会重定向或刷新(最终请访问www.evanciniello.ca/php/submit.php)
问题二:邮件本身在我的收件箱中不可见(即我可以看到谁发送了电子邮件但无法阅读邮件)。
与HTML表单联系
<div id="container" class="clearfix">
<div class="element clearfix col2-3 contact">
<form id="contact-us" action="/php/submit.php" method="post">
<h1>Contact Us!</h1>
<input type="text" name="first_name" placeholder="NAME" required>
<input type="email" name="email" placeholder="MAIL" required>
<textarea name="message" placeholder="MESSAGE" required ></textarea>
<input id="button" type="submit" class="submit"></button>
</form>
<div id="error" style="display:none;"> Please Provide Valid Information</div>
</div>
</div>
PHP表格
<?php
if(isset($_POST['submit'])) {
$to = "contact@evanciniello.ca";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
$success = mail($to, $subject, $body);
}
?>
答案 0 :(得分:2)
这很正常。在/php/submit.php
if (isset($_POST['submit'])) {
if (empty($_POST["message"]) || empty($_POST["first_name"]) || empty($_POST["email"])) {
//Set up some error messages here and show that to the users.
} else {
$to = "contact@evanciniello.ca";
$subject = "Form Tutorial";
$name_field = $_POST['first_name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
$success = mail($to, $subject, $body);
if ($succes) {
//Now we need to redirect
$url = "http://www.evanciniello.ca/WHEREYOUWANTTOREDIRECT";
Header("Location: " . $url);
} else {
//Set up error message, that message can not be setn
die("Message can not be sent");
}
}
}
在提交中添加name
:
<input id="button" type="submit" class="submit" name="submit"></button>