无法从我的网站接收申请表中的邮件

时间:2018-09-29 07:27:59

标签: php html css

我在我的网站上添加了一份培训申请表。使用模态框。这是代码

<button type="submit" onclick="document.getElementById('id01').style.display='block'" style="width:auto;">Apply Now</button>

<div id="id01" class="modal">
  <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">&times;</span>
  <form method="POST" enctype="multipart/form-data" class="modal-content" action="sendemailcontact.php">
    <div class="container">
      <h1>Application Form</h1>
      <p>Please fill in this form to apply for the training.</p>
      <hr>
       <label for="name"><b>Name</b></label><br>
      <input type="text" placeholder="Enter name" name="name" id="name" required><br>
      <label for="email"><b>Email</b></label><br>
      <input type="text" placeholder="Enter Email" name="email" id="email" required><br>
      <label for="phone"><b>Phone number</b></label><br>
      <input type="text" placeholder="Enter phone number" name="phone" id="phone" required><br>
      
      <label for="location"><b>Location</b></label><br>
      <input type="text" placeholder="Enter location" name="location" id="location" required><br>
       <label for="college"><b>College</b></label><br>
      <input type="text" placeholder="Enter college" name="college" id="college" required><br>
<!--<label for="uploaded_file"><b>Upload resume</b></label>
      <input class="upl" type="file" name="uploaded_file" id="uploaded_file"  required>-->
      <div class="clearfix">
        
        <input style="width:30%;" type="submit" name="apply" id="apply" class="signupbtn" value="Apply">
      </div>
    </div>
  </form>
</div>

此表格发送给我的php代码,该表格将邮件发送到我的电子邮件地址,该电子邮件地址是通过上述表格从每个申请人那里收到的详细信息。这是我的php代码

<?php 

//error_reporting(-1);
//ini_set('display_errors', 'On');
//set_error_handler("var_dump");


$errors = '';
$myemail = 'example@gmail.com';
if(empty($_POST['name'])  || 
   empty($_POST['email']) ||
   empty($_POST['phone']) ||
   empty($_POST['location']) ||
   empty($_POST['college']))
{
    $errors .= "\n Error: all fields are required";
}


$email_address = $_POST['email']; 
$name = $_POST['name']; 
$phno = $_POST['phone']; 
$location = $_POST['location']; 
$college = $_POST['college']; 

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 = "Career Oriented Training Form submission: $name";
    $email_body = "You have received a new applicant. ".
    " Here are the details:\n Name: $name \n Email: $email_address \n Phone: $phno  \n Location: $location \n College: $college"; 

    $headers = "From: $email_address\n"; 
    $headers .= "Reply-To: $myemail";

    mail($to,$email_subject,$email_body,$headers);

    header('Location:index.html');
} 
?>

当我单击提交时,其将进入空白页。我也无法收到任何邮件。请帮助我

1 个答案:

答案 0 :(得分:0)

您需要让它回显$ errors,因为这将告诉您为什么它会失败。您要储备$ errors并忽略它,而不是检查它是否为空。

使用正则表达式来验证电子邮件地址。具体参见https://emberjs.com/api/ember/3.4/classes/Ember.Templates.helpers FILTER_VALIDATE_EMAIL