没有通过PHP通过电子邮件发送表单值?

时间:2015-04-30 15:41:52

标签: php html email

我试图将html表单中的值邮寄到带有php的电子邮件地址。但是,当我尝试通过电子邮件发送表单时,它会发送但电子邮件中没有值? Php不是我的区域,我会提供一些帮助:到目前为止,我的代码是:

HTML

<form class="form-horizontal" action="send_mail.php" method="post">


<br />
<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" >
    provider name *
  </label>

  <div class="col-md-8">
    <input id="providername" type="text" name="providername" class="form-control input-md" required="">

  </div>
</div>



<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" >
    Address Line 1 *
  </label>

  <div class="col-md-8">
    <input id="address1" name="address1" type="text" placeholder="" class="form-control input-md" required="">

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" >
    Address Line 2 *
  </label>

  <div class="col-md-8">
    <input id="address2" name="address2" type="text" placeholder="" class="form-control input-md" required="">

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label">
    Post Code *
  </label>

  <div class="col-md-8">
    <input id="postcode" name="postcode" type="text" placeholder="" class="form-control input-md" required="">

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label">
    ID *
  </label>

  <div class="col-md-8">
    <input id="id" name="id" type="text" class="form-control input-md" required="">

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" >
    Primary contact *
  </label>

  <div class="col-md-8">
    <input id="primarycontact" name="primarycontact" type="text" class="form-control input-md" required="">

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" >
    Job title *
  </label>

  <div class="col-md-8">
    <input id="job" name="job" type="text" class="form-control input-md" required="">

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label">
    Name contact email *
  </label>

  <div class="col-md-8">
    <input id="email" name="email" type="text" class="form-control input-md" required="">

  </div>
</div>

<!-- Text input-->
<div class="form-group">
  <label class="col-md-4 control-label" >
    Name contact phone number *
  </label>

  <div class="col-md-8">
    <input id="contact2" name="contact2" type="number" class="form-control input-md" required="">

  </div>
</div>

<!-- Button -->
<div class="form-group">
  <label class="col-md-4 control-label" for="singlebutton">
  </label>
  <div class="col-md-4">
    <input class="btn btn-primary" type="submit" value="Submit">
  </div>
</div>

PHP:

<?php

$webmaster_email = "my_email@yahoo.com";


$feedback_page = "feedback_form.html";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";


$email_address = $_REQUEST['email_address'] ;
$providername = $_REQUEST['providername'] ;
$address1 = $_REQUEST['address1'] ;
$address2 = $_REQUEST['address2'] ;
$postcode = $_REQUEST['potscode'] ;
$nctlid = $_REQUEST['nctlid'] ;
$contact = $_REQUEST['contact'] ;
$job = $_REQUEST['job'] ;
$email = $_REQUEST['email'] ;
$contact2 = $_REQUEST['contact2'] ;



function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
    return true;
}
else {
    return false;
}
}


if (!isset($_REQUEST['email_address'])) {
header( "Location: $feedback_page" );
}


elseif (empty($email_address) ) {
header( "Location: $error_page" );
}


elseif ( isInjected($email_address) ) {
header( "Location: $error_page" );
}


else {
mail( "$webmaster_email", "Feedback Form Results",
$email_address, $providername, "From: $email_address" );
header( "Location: $thankyou_page" );
}
?>

谢谢

1 个答案:

答案 0 :(得分:0)

从您的PHP脚本中, $ _ REQUEST [&#39; email_address&#39;] 似乎不存在于您的html表单或您的网址查询参数中。

确保您从html表单或其他来源发布 email_address 的值。