我的HTML / PHP表单有问题

时间:2016-06-16 11:30:17

标签: php html

游戏的新手并尝试整理表格,如标题所示,我没有运气。

我自己编写了这个表单,但是从教程中捏了一下php并略微改变了一些东西以适应但是所有发生的事情都是用" fields1,2,3和#34重定向到同一页面;在我的网址中。

如果有人对如何做到这一点有任何建议,那就太棒了!

干杯,

w ^

P.S。我知道我的电子邮件也是test@email.com:)

HTML

<form>
    <form action="form-to-mail.php" method="POST">
    <ul class="form-style-1">
      <li><label>Full Name <span class="required">*</span></label><input type="text" name="field1" class="field-divided" placeholder="First" />&nbsp;<input type="text" name="field2" class="field-divided" placeholder="Last" /></li>
      <li>
        <label>Email <span class="required">*</span></label>
        <input type="email" placeholder="Email" name="field3" class="field-long" />
      </li>

      <li>
        <label>Tell us a little bit about what you do<span class="required">*</span></label>
        <textarea name="field4" id="field4" class="field-long field-textarea"></textarea>
      </li>
      <li>
        <label>What are you selling? <span class="required">*</span></label>
        <textarea name="field5" id="field5" class="field-long field-textarea"></textarea>
      </li>
      <li>
        <label>How did you hear about FOCUS? <span class="required">*</span></label>
        <textarea name="field6" id="field6" class="field-long field-textarea"></textarea>
      </li>
      <li>
        <input type="submit" value="Submit" />
      </li>
    </ul>
  </form>

PHP

<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$field1 = $_POST['field1'];
$field2 = $_POST['field2'];
$field3 = $_POST['field3'];
$field4 = $_POST['field4'];
$field5 = $_POST['field5'];
$field6 = $_POST['field6'];

//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}

if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}

$email_from = 'test@email.com';
$email_subject = "FOCUS Application";
$email_body = "$field1, $field2, $field3, $field4, $field5, $field6";

$to = "test@email.com";
$headers = "From: <$email_from> \r\n";
$headers .= "Reply-To: <$visitor_email> \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');


// Function to validate against any email injection attempts
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;
}
}

?>

0 个答案:

没有答案