使用php发送电子邮件不起作用?

时间:2015-08-25 20:17:51

标签: php email

我将以下代码作为一个名为contact.php的文件发送到指定的电子邮件地址,但是当它运行时,它会显示确认已发送电子邮件“我们已收到您的请求,但电子邮件不是被发送到指定的电子邮件地址..任何人都知道我的代码中是否存在缺陷?

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

     ?> 

0 个答案:

没有答案