此PHP表单是在暂存网站上构建的,用于测试。在该暂存站点上填写表单后,它将正确地将电子邮件发送到myemail。此代码已上传到产品网站上,无论出于何种原因,无论何时提交表单,包括正确检查所有字段以进行验证时,表单都会刷新并显示一条验证消息,指出所有字段都是必需的。在登台站点上不会发生此问题,并且正在发送联系人电子邮件。在产品服务器上,将引发错误,并且没有发送联系电子邮件。我们不确定为什么会这样-任何清晰度都将不胜感激。登台运行5.3,Prod运行5.4并在Godaddy上运行。 Postmaxsize = 128mb。
HTML for Form
<!-- Form Section -->
<br>
<div class="section_container_500">
<form id="contact_form" method="POST" name="contactform" action="contact-form-handler.php">
<p class="contact_error_text">Oops! All fields are required.</p>
<p>
<label for="name">Full Name<span style="color: red;">*</span></label> <br>
<input class="text_input" type="text" name="name">
</p>
<p>
<label for="email">Email Address<span style="color: red;">*</span></label> <br>
<input class="text_input" type="text" name="email">
<br>
</p>
<p>
<label for="user">I am a…</label> <br>
<select class="text_input" name="user">
<option value="patient">Patient</option>
<option value="HSP">Health Service Provider</option>
<option value="investor">Investor</option>
<option value="other">Other</option>
</select>
</p>
<p>
<label for="phone">Phone Number (Optional)</label> <br>
<input class="text_input" type="tel" name="phone"> <br>
</p>
<p>
<label for="message">Message<span style="color: red;">*</span>:</label> <br>
<textarea class="text_input" name="message"></textarea>
</p>
<input class="mid_CTA, form_submit" style="display: block; margin: auto;" type="submit" value="Send"><br>
</form>
</div>
<br><br>
PHP for Form
<!-- Code for validating the form -->
<script>
var frmvalidator = new Validator("contactform");
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
</script>
<?php
$errors = '';
$myemail = 'fake@fakeemail.com';
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$user = $_POST['user'];
$phone = $_POST['phone'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n Email: $email_address \n User Type: $user \n Phone: $phone \n Message: $message";