简体   繁体   English

我在我的网站上收到空电子邮件

[英]I am receiving empty emails on my website

I am building a html5 based contact form with php mail script. 我正在使用php邮件脚本构建基于html5的联系表单。

I do not know why i am getting empty emails on submission as well as If i want to print any message like "Thank you for contacting us", How would I do that. 我不知道为什么我在提交时会收到空电子邮件,以及如果我想打印任何消息,例如“谢谢您与我们联系”,我将如何处理。

<?php
$name = (isset($_POST['name']) ? $_POST['name'] : null);
$phone = (isset($_POST['phone']) ? $_POST['phone'] : null);
$address = (isset($_POST['address']) ? $_POST['address'] : null);
$appointment_datepicker =(isset($_POST['appointment-datepicker']) ? $_POST['appointment-datepicker'] : null);
$message = (isset($_POST['textarea']) ? $_POST['textarea'] : null);
$email_address = (isset($_POST['email']) ? $_POST['email'] : null);



// Create the email and send the message
$to = 'dipen2512@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form:  $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nPhone: $phone\n\nEmail: $email_address\n\nAppointment: $appointment_datepicker\n\nAddress: $address\n\nMessage:\n$message";
$headers = "From: noreply@dev-designers.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address"; 
$mail_status = mail($to,$email_subject,$email_body,$headers);   

/** Check for empty fields
if(!empty($_POST['name']) || !empty($_POST['phone']) || !empty($_POST['address']) || !empty($_POST['appointment-datepicker']) || !empty($_POST['textarea'])  || filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{**/
 if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
      print( "Thank you for the message. We will contact you shortly.");
        window.location = 'http://thankyou.html';
    </script>
  <?php
  }

else { ?>
   <script language="javascript" type="text/javascript">
      print( 'Message failed. Please, send an email to gordon@template-help.com');
      window.location = 'http://thankyou.html';
   </script>
<?php
}
?>

<form id="appointment-form" action="contact_me.php" method="post" class="appointment-form">
                                    <div class="col-md-6">
                                        <div class="form-group form-md-line-input form-md-floating-label">
                                            <input id="name" type="text" class="form-control" required="required">
                                            <label for="name">Name</label>
                                        </div>
                                        <div class="form-group form-md-line-input form-md-floating-label">
                                            <input id="phone" type="text" class="form-control" required="required" pattern="/[1-9][01][0-9]-?[0-9]{3}-=[0-9]{4}">
                                            <label for="phone">Phone Number</label>
                                        </div>
                                        <div class="form-group form-md-line-input form-md-floating-label">
                                            <input id="address" type="text" class="form-control" required="required">
                                            <label for="address">Address </label>
                                        </div>
                                        <div class="form-group form-md-line-input form-md-floating-label">
                                            <input id="appointment-datepicker" type="text" class="form-control form-line-input" required="required">
                                            <label for="appointment-datepicker">Book a date</label>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group form-md-line-input form-md-floating-label">
                                            <input id="email" type="text" class="form-control" required="required" pattern="[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*">
                                            <label for="email">Email Address</label>
                                        </div>
                                        <div class="form-group form-md-line-input form-md-floating-label">
                                            <textarea id="textarea" rows="4" class="form-control form-textarea"></textarea>
                                            <label for="textarea">Message</label>
                                        </div>
                                        <div class="btn-wrapper">
                                            <button type="submit" class="btn btn-make-app">Send to us</button>
                                        </div>
                                    </div>
                                    <div class="clearfix"> </div>
                                </form>

Your form inputs are missing "name" attributes. 您的表单输入缺少“名称”属性。 IDs don't get passed along in a form request; ID不会在表单请求中传递; only the name-value pairings. 仅名称/值配对。

                 v---------v
<input id="name" name="name" type="text" class="form-control" required="required">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM