0

I have the following code as a file named contact.php which is to send an email to the designated email address but as it runs it appears acknowledge it has sent an email as "we have received your request but the email does not get sent to the designated email address.. Anyone know if there is a flaw in my code?

          <?php 
          $to ="Your email address"; 
          $subject = "Reservation"; 
          $name = $_REQUEST['name'] ;
          $phone = $_REQUEST['phone'] ;
          $email = $_REQUEST['email'] ; 
          $day = $_REQUEST['day'] ;
          $month = $_REQUEST['month'] ;
          $year = $_REQUEST['year'] ;
          $people = $_REQUEST['people'] ;
          $comments = $_REQUEST['comments'] ; 

          function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
            }

       $email_message .= "Name:  $name   \n";
       $email_message .= "Phone: $phone  \n";
       $email_message .= "Email: $email  \n";
       $email_message .= "Date: $day $month $year  \n";
       $email_message .= "No. of People: $people  \n";
       $email_message .= "Comments: $comments  \n";

       $headers = "From: $email"; 
       $sent = mail($to, $subject, $email_message, $headers) ; 

       if ($sent)
       {
       // Successful popup message, redirected back to view contacts
       echo "<script type='text/javascript'>alert('We have received your         Reservation Request'); window.location.href = 'reservation.html';</script>";
          }
       else
        {
    // Unsuccessful popup message, redirected back to view contacts
    echo "<script type='text/javascript'>alert('There was an Error! Please try again.'); window.location.href = 'reservation.html';</script>";
     }

     ?> 
Shane Reen
  • 21
  • 5
  • Try using print_r(error_get_last()) after your mail() function, this should help you debug it – Bryant Frankford Aug 25 '15 at 20:19
  • always my first step in cases like this is to check the mail server log. –  Aug 25 '15 at 20:20
  • @BryantFrankford hes mail function returns true. not that it means a whole lot. –  Aug 25 '15 at 20:21
  • It seems to run the If, else part of code but the mail does't send so there must be something wrong with my mail function. This same code worked as recently as three days ago but for some reason doesn't send the email anymore? – Shane Reen Aug 25 '15 at 20:56

0 Answers0