为什么我的PHP电子邮件不起作用?

时间:2013-05-28 19:11:43

标签: php html

<form name="contacteer" method="post">
  <table align="center">
    <tr>
      <td><p>Naam:*</p></td>
      <td> <input type="text" name="naam"></td>
    </tr>
    <tr>
      <td><p>Bedrijf:</p></td>
      <td><input type="text" name="bedrijf"></td>
    </tr>
    <tr>
      <td><p>E-mail:*</p></td>
      <td><input type="text" name="email"></td>
    </tr>
    <tr>
      <td><p>Bericht:</p></td>
      <td><input type="text" name="bericht" class="contact_bericht"></td>
    </tr>
    <tr>
      <td></td>
      <td><input type="submit" name='submit' value="verstuur" class="contact_submit"></td>
    </tr>
  </table>
</form>

<?php 
  if(isset($POST['submit'])
  {
    $email_to = "webmaster@centrum4games.com";
    $email_subject = "Friespepermunt Contact Formulier";
    $naam = $_POST['naam'];
    $bedrijf = $_POST['bedrijf'];
    $email = $_POST['email'];
    $bericht = $_POST['bericht']; 

    $email_message .= "Naam: ".$naam."\n";
    $email_message .= "Bedrijf: ".$bedrijf."\n";
    $email_message .= "Email: ".$email."\n";
    $email_message .= "Bericht: ".$bericht."\n";

    $headers = 'From: '.$email."\r\n".
    'Reply-To: '.$email."\r\n" .
    'X-Mailer: PHP/' . phpversion();

    mail( $email_to, $email_subject, $email_message, $headers ) ;

  }
?>

它没有发送,为什么?我有点卡住,我确信这是一个很小的错误,但我似乎无法找到它:/

2 个答案:

答案 0 :(得分:1)

<强>测试

您遇到的两个语法错误:
if(isset($POST['submit'])

您错过了$_POST和遗失/关闭)

更改为:if(isset($_POST['submit']))

另外,我添加了action="<?php echo $_SERVER['PHP_SELF']; ?>"

<form name="contacteer" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <table align="center">
    <tr>
      <td><p>Naam:*</p></td>
      <td> <input type="text" name="naam"></td>
    </tr>
    <tr>
      <td><p>Bedrijf:</p></td>
      <td><input type="text" name="bedrijf"></td>
    </tr>
    <tr>
      <td><p>E-mail:*</p></td>
      <td><input type="text" name="email"></td>
    </tr>
    <tr>
      <td><p>Bericht:</p></td>
      <td><input type="text" name="bericht" class="contact_bericht"></td>
    </tr>
    <tr>
      <td></td>
      <td><input type="submit" name='submit' value="verstuur" class="contact_submit"></td>
    </tr>
  </table>
</form>

<?php 
  if(isset($_POST['submit']))
  {
    $email_to = "webmaster@centrum4games.com";
    $email_subject = "Friespepermunt Contact Formulier";
    $naam = $_POST['naam'];
    $bedrijf = $_POST['bedrijf'];
    $email = $_POST['email'];
    $bericht = $_POST['bericht']; 

    $email_message .= "Naam: ".$naam."\n";
    $email_message .= "Bedrijf: ".$bedrijf."\n";
    $email_message .= "Email: ".$email."\n";
    $email_message .= "Bericht: ".$bericht."\n";

    $headers = 'From: '.$email."\r\n".
    'Reply-To: '.$email."\r\n" .
    'X-Mailer: PHP/' . phpversion();

    mail( $email_to, $email_subject, $email_message, $headers ) ;

  }
?>

答案 1 :(得分:0)

第一行PHP代码:if(isset($POST['submit'])。缺少下划线,应为if(isset($_POST['submit'])