Контактная форма не отправляет письмо - PullRequest
0 голосов
/ 18 апреля 2011

Я пишу свою первую в истории контактную форму PHP.Я работал над этим весь день.Просматривая все в Google, и я не могу получить ответ.Контакт с отправляется на страницу успеха, и все равно ничего не попадает в мой почтовый ящик ...........

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
  }
  ?>

Что-то не так с этим?

Вот 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 --> 

Может кто-нибудь взглянуть на это?Я уверен, что все сделал правильно .....

Ответы [ 2 ]

0 голосов
/ 18 апреля 2011

изменить эту строку:

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

до:

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

это может быть проблемой

0 голосов
/ 18 апреля 2011

По крайней мере, ваша строка

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

кажется неправильной, перед mail.

должен стоять знак равенства.
...