没有从html发布的PHP发送邮件的值

时间:2018-03-21 08:19:14

标签: php html

我有一个html表单,我需要从PHP发送邮件。 我能够发送邮件,但它没有从html中获取值。

HTML表单:

<form id="main-contact-form" name="application-form" method="post" action="Applyonline.php">

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

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

  <div class="form-group">
    <input type="text" name="phno" class="form-control" placeholder="Phone Number" required="required" maxlength="10">
  </div>

  <div class="form-group">
    <label for="working">Are You Presently Working</label>
    <input type="radio" name="working" value="yes" checked> Yes
    <input type="radio" name="working" value="no"> No
  </div>
  <div class="form-group">
              <button type="submit" class="btn-submit">Apply Now</button>
            </div>
    </form>

PHP代码:

 <?php $name       = @trim(stripslashes($_POST['name']));
 $qualification = @trim(stripslashes($_POST['qualification'])); $phno =
 @trim(stripslashes($_POST['phno']));
 $working=@trim(stripslashes($_POST['working']));

 $subject    = "Application";

 $to        = 'wc@example.com';//replace with your email



 $message    =  " <html> <head>

 </head> <body> <p>This email contains HTML Tags!</p> <table> <tr>
 <td>Candidate Name:</th> <td>$name</td> </tr>

 <tr> <td>Qualification:</th> <td>$qualification</td> </tr> <tr>
 <td>Phone Number:</th> <td>$phno</td> </tr> <tr> <td>Are you
 Presently Woring:</th> <td>$working</td> </tr>

 </table> </body> </html> ";

 // Always set content-type when sending HTML email $headers =
 "MIME-Version: 1.0" . "\r\n"; $headers .=
 "Content-type:text/html;charset=UTF-8" . "\r\n"; // More headers
 $headers .= 'From: <$from>' . "\r\n";

 mail($to, $subject, $message, $headers);

 ?>

它不接受$ name,$ qualified等的值...我没有得到上述形式的问题。

请提前帮助,谢谢。

1 个答案:

答案 0 :(得分:0)

$message中,您将<>放在变量周围,这些变量将被解释为HTML标记,因此不会显示在您的邮件中。将您的$message替换为

$message    =  " <html> <head>
</head> <body> <p>This email contains HTML Tags!</p> <table> <tr>
<td>Candidate Name:</td> <td>$name</td> </tr>
<tr> <td>Qualification:</td> <td>$qualification</td> </tr> <tr>
<td>Phone Number:</td> <td>$phno</td> </tr> <tr> <td>Are you
Presently Working:</td> <td>$working</td> </tr>
</table> </body> </html> ";

它们应该出现在你的邮件中。

相关问题