我正在努力让我的联系表格得以运作。当我填写表单并单击“发送”时,它会重定向到contact.php
,并且不会发送电子邮件或工作。谁能帮助我并解释我的代码有什么问题?这是下面的代码:
<div id="zContact_form">
<center><?php echo $text;?></center>
<strong>We will reply within 15 minutes, that's a Promise!!. </strong>
<form name="form1" id="ff" method="post" action="contact.php">
<label>
Name*:
<input type="text" placeholder="Please enter your name" name="name" id="name" required>
</label>
<label>
Email*:
<input type="email" placeholder="info@youbelizetours.com" name="email" id="email" required>
</label>
<label>
Message*:
<textarea name="message" id="message">Please enter your message</textarea>
</label>
<input class="sendButton" type="submit" name="Submit" value="Send">
</form>
<?php
$text = "<span style='color:red; font-size: 35px; line-height: 40px; magin: 10px;'>Error! Please try again.</span>";
if(isset($_POST['name'])){
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$to = "youbelizetours@gmail.com";
$subject = "Tour Reservations from Edwin's Adventure Tours";
$message = " Name: " . $name ."\r\n Email: " . $email . "\r\n Message:\r\n" . $message;
$from = "$name";
$headers = "From:" . $from . "\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";
if(mail($to,$subject,$message,$headers)){
$text = "<span style='color:blue; font-size: 35px; line-height: 40px; margin: 10px;'>Your Message was sent successfully !</span>";
}
}
?>
代码有什么问题吗?或者它可能是我没有看到的其他东西。
答案 0 :(得分:0)
我能看到的是在最后一个$ _POST中缺少结束括号。其余的代码似乎很好,我提供contact.php是单独的文件或整个代码在contact.php。我使用form action=""
<?php
$text = "<span style='color:red; font-size: 35px; line-height: 40px; magin: 10px;'>Error! Please try again.</span>";
if(isset($_POST['name']))
{
var_dump($_POST);
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$to = "youbelizetours@gmail.com";
$subject = "Tour Reservations from Edwin's Adventure Tours";
$message = " Name: " . $name ."\r\n Email: " . $email . "\r\n Message:\r\n" . $message;
$from = "$name";
$headers = "From:" . $from . "\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n";
if(mail($to,$subject,$message,$headers))
{
$text = "<span style='color:blue; font-size: 35px; line-height: 40px; margin: 10px;'>Your Message was sent successfully !</span>";
}
}
?>
<div id="zContact_form">
<center><?php echo $text;?></center>
<strong>We will reply within 15 minutes, that's a Promise!!.</strong>
<form name="form1" id="ff" method="post" action="">
<label>
Name*:
<input type="text" placeholder="Please enter your name" name="name" id="name" required>
</label>
<label>
Email*:
<input type="email" placeholder="info@youbelizetours.com" name="email" id="email" required>
</label>
<label>
Message*:
<textarea name="message" id="message">Please enter your message</textarea>
</label>
<input class="sendButton" type="submit" name="Submit" value="Send">
</form>
</div>