简体   繁体   English

联系表格未发送电子邮件

[英]Contact form not sending email

I'm coding my first ever PHP contact form. 我正在编写我的第一个PHP联系人表格。 I've been working on it all day. 我整天都在努力。 Looking up everything on Google and I can't get a answer. 寻找在谷歌的一切,我不能得到一个答案。 The contact from goes to the success page and still nothing goes into my inbox........... 联系人从转到成功页面,但仍然没有任何内容进入我的收件箱...........

PHP: PHP:

<?php
  // Define some constants
  define( "RECIPIENT_NAME", "name" );
  define( "RECIPIENT_EMAIL", "name@gmail.com" );
  define( "EMAIL_SUBJECT", "Message" );

  // Read the form values
  $success = false;
  $sender = isset( $_POST['sender'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['sender'] ) : "";
  $email = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email'] ) : "";
  $message = isset( $_POST['message'] ) ?  preg_replace( "/(From: |To: |BCC: |CC: |Subject: |Content-Type:)/", "", $_POST['message'] ) : "";

  //If all values exist, send the email 
  if ( $sender && $email && $message ) {
    $recipient = RECIPIENT_NAME . " <" . RECIPENT_EMAIL . $email . ">";
    $headers = "From: " . $sender . " <" . $email . ">";
    $success = mail( $recipient, EMAIL_SUBJECT, $message, $headers );
  }

  // Return an appropriate reponse to the browser
  if( isset($_GET["ajax"]) ) {
    echo $success ? "success" : "error";
  } else {
  ?>
  <html>
    <head>
    <title>Thanks!</title>
    </head>
    <body>
      <?php if ( $success ) echo "<h2>Thanks for sending your message! We'll get back to you shortly.</h2>" ?>
      <?php if ( !$success ) echo "<h2> Sorry, There was a problem sending your message. Please try again.</h2>" ?>
      <p> Click your browser's back button to return to the page</p>
    </body>
  </html>
  <?php
  }
  ?>

Is there anything wrong with it? 这有什么问题吗?

Heres the HTML 继承人的HTML

<form id="contactForm" action="process.php" method="post"> 
  <label for="sender">Your Name</label> 
  <input type="text" name="sender" id="sender" placeholder="Your Name" required="required" maxlength="40"> 

  <label for="email">Your Email Address</label> 
  <input type="email" name="email" id="email" placeholder="Please type your email address"
  required="required" maxlength="50"> 

  <label for="message">Your Message</label> 
      <textarea name="message" id="message" placeholder="Please type your message" required="required"
       cols="50" rows="5" maxlength="10000"></textarea>     

  <div id="form-buttons"> 
    <input type="submit" id="send-message" name="send-message" value="Send Email" /> 
    <input type="button" id="cancel" name="cancel" value="Cancel" /> 
  </div><!-- #form-buttons --> 

Could someone take a look at this? 有人可以看看吗? I'm sure I did everything right..... 我确定我做对了所有事情.....

At least your line 至少你的线

$success mail( $recipient, EMAIL_SUBJECT, $message, $headers );

seems wrong, there should be an equality sign before mail . 似乎错了,在mail之前应该有一个等号。

change this line: 更改此行:

$recipient = RECIPIENT_NAME . " <" . RECIPENT_EMAIL . $email . ">";

to: 至:

$recipient = RECIPIENT_NAME . " <" . RECIPENT_EMAIL . ">";

that might be the issue 那可能是问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM