嘿所以我需要为我正在处理的网站联系我们表格,并且我在使用正确的语法将表单数据正确发送到电子邮件帐户时遇到了一些麻烦。
现在的问题是当我点击提交按钮时,没有任何反应。没有发送电子邮件,HTML页面本身也没有任何反应。
这是我的代码:
<div class="row-fluid">
<div class="span12">
<div class="status alert alert-success" style="display: none"></div>
<form style="margin-left:5%;margin-right:5%;" id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="row-fluid">
<div class="span5">
<label>Full Name *</label>
<input name="name" type="text" class="input-block-level" required="required" placeholder="John Smith">
<label>Email Address *</label>
<input name="email" type="email" class="input-block-level" required="required" placeholder="example@domain.com">
<label>Phone</label>
<input type="text" name="phone" required="required" class="input-block-level" placeholder="(123) 456-7890">
</div>
<div class="span7">
<label>Message *</label>
<textarea name="message" id="message" required="required" class="input-block-level" rows="8"></textarea>
</div>
</div>
<div class="center">
<input value="submit" type="submit" name="submit" required="required" class="btn btn-primary btn-large">
</div>
</form>
</div>
</div>
</div>
-
<?php
if (isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$from = "mail@company.com";
$to = "company@company.com";
$subject = "Contact Us Submission - Company";
$body = "Here is the contact form submission information:\n\nName:\n $name\n\n E-Mail:\n $email\n\n Phone:\n $phone\n\n Message:\n $message";
$userto = "$email";
$usersubject = "Thank you, from Company.";
$userbody = "Dear $name,\n\nWe have received your response from the Company Contact Us form and will be in touch shortly. If you have any questions, please do not hesitate to ask us.\nYou can simply reply to this email at mail@company.com\n\nSincerely,\nCompany";
}
if ((mail($to, $subject, $body) && mail($userto, $usersubject, $userbody))
{
echo "<p>Thank you. Your response was received. You can now close this tab.</p>";
}
else
{
echo "<p>Sorry, there was an error sending your response. Please try again. If the problem persits, please contact Company via another method.</p>";
}
?>
答案 0 :(得分:0)
表单本身很好,但我个人删除了目标=&#39; _blank&#39;但是,php中存在语法错误。
将以上行更改为:
if ( mail($to, $subject, $body) && mail($userto, $usersubject, $userbody) ) {
echo "<p>Thank you. Your response was received. You can now close this tab.</p>";
} else {
echo "<p>Sorry, there was an error sending your response. Please try again. If the problem persits, please contact Company via another method.</p>";
}