douliu3831 2016-06-27 14:13
浏览 24
已采纳

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

I am building a html5 based contact form with php mail script.

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.

"."Here are the details:

Name: $name

Phone: $phone

Email: $email_address

Appointment: $appointment_datepicker

Address: $address

Message:
$message";
$headers = "From: noreply@dev-designers.com
"; // 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>
  • 写回答

1条回答 默认 最新

  • dqf98772 2016-06-27 14:17
    关注

    Your form inputs are missing "name" attributes. IDs don't get passed along in a form request; only the name-value pairings.

                     v---------v
    <input id="name" name="name" type="text" class="form-control" required="required">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败