2016-03-16 123 views
0

我的表单有姓名,电子邮件,电话&消息字段不起作用。当我提交表单时,空白页面将以php邮件处理程序url打开。它应该显示感谢信息。电子邮件ID也不会收到电子邮件。请帮忙。PHP表单不能正常显示空白页面

我的HTML表单代码是

<form id="contactform" action="contact_form.php" method="POST"> 
      <div> 
      <input type="text" class="form-control" placeholder="Name" name="name" required id="name"> 
      </div> 
      <div> 
      <input type="email" class="form-control" placeholder="Email" name="email" required id="email"> 
      </div> 
      <div> 
      <input type="text" class="form-control" placeholder="Phone" required name="phone" id="phone"> 
      </div> 
      <textarea class="form-control" name="message" id="message" rows="4" placeholder="Enter Your Message" required></textarea> 

      <div class="text-center"> 
      <button type="submit" value="submit" class="btn btn-default">SUBMIT</button> 
      </div> 
     </form> 

PHP代码的邮件

<?php 
if(isset($_POST['submit'])){ 
    $to = "[email protected]"; // this is your Email address 
    $from = $_POST['email']; // this is the sender's Email address 
    $name = $_POST['name']; 
    $phone = $_POST['phone']; 
    $subject = "Form submission"; 
    $subject2 = "Copy of your form submission"; 
    $message = "Name:". $name . "\n" . "Phone:" . $phone . "\n" . "\n" . "Message:" . "\n" . $_POST['message']; 
    $message2 = "Here is a copy of your message " . "\n" . "Name:" . $name . "\n" . "Phone:" . $phone . "\n" . "\n" . "Message:" . "\n" . $_POST['message']; 
    $headers = "From:" . $from; 
    $headers2 = "From:" . $to; 
    mail($to,$subject,$message,$headers); 
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender 
    echo "Mail Sent. Thank you, " . $name . ", we will contact you shortly."; 
    // You can also use header('Location: thank_you.php'); to redirect to another page. 
    // You cannot use header and echo together. It's one or the other. 
    } 
?> 

的形式是在这个页面的底部 https://www.delveindia.com/products/billing-software/

+0

如果它在本地,那么你需要做一些更多的东西。搜索如何通过PHP中的本地主机发送邮件,你会得到大量的例子。 –

+0

它托管在Cpanel服务器上。 – 1bunty1

+0

要求您的服务器提供商在您的服务器上进行邮件设置。没有邮件将不会发送 –

回答

2

我相信你的按钮没有名字。 $ _POST ['submit']不能设置,因为没有任何命名提交。

给你的按钮名称,提交:)

+0

作出了你建议的更改,仍然不工作:( – 1bunty1