html表单与.php文件连接,但它没有发送邮件

时间:2018-04-02 04:45:53

标签: php html

//这是html文件

<form role="form" action="mail.php" method="post">

      <div class="form-group">
        <input type="text" class="form-control" id="name" name="name" placeholder="Name" required>
       </div>

       <div class="form-group">
         <input type="text" class="form-control" id="email" name="email" placeholder="Email" required>
       </div>

       <div class="form-group">
         <input type="text" class="form-control" id="mobile" name="mobile" placeholder="Contact No." required>
       </div>

       <div class="form-group">
           <textarea name="comment" class="form-control" type="textarea" id="message" placeholder="Comment on services required" rows="7"></textarea>     
     </div>

       <button type="submit" id="submit" name="submit" class="btn btn-primary">Submit Mail
       </button>

          </form>

//这是附加到上面的html文件的php文件

//在提交此代码后我没有收到邮件。

    <?php
    if (isset($_POST['submit']))
    {
        $sender_name=stripslashes($_POST["name"]);
        $sender_email=stripslashes($_POST["email"]);
        $sender_mobile=stripslashes($_POST["mobile"]);
        $sender_message=stripslashes($_POST["comment"]);

        $subject = "Enquiry Form";

        $body  = " \n";
        $body .= " Name : ".$sender_name."\n";
        $body .= " Email : ".$sender_email."\n";
        $body .= " Mobile : ".$sender_mobile."\n";
        $body .= " Brief : ".$sender_message."\n";


        $to = "shubham.tropicalcluster@gmail.com";

        if(mail($to, $subject, $body, "From: $sender_email")) {
           header('Location:thanks.html');
        }    
    }

    else {
        echo "ERROR SHUBHAM";
    }
    ?>

//我可以获得一个可以运行我的所有形式的代码意味着通用.php文件以html格式邮寄所有细节

1 个答案:

答案 0 :(得分:0)

请在mail.php文件中添加以下脚本。 (将其重命名为custommail.php)。您可以检查您的服务器是否会发送电子邮件。

<?php
// the message
$msg = "First line of text\nSecond line of text";

// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);

// send email
mail("shubham.tropicalcluster@gmail.com","My subject",$msg);
?>