1

こんにちは、お問い合わせフォームからメールを送信するための PHP コードに問題があります。フォームは以前は機能していましたが、電子メールの送信を停止しました。私はphpが初めてなので、助けてください.エラーは発生せず、コードを徹底的に調査した後、コードに問題はありません.誰かが私を助けてくれますか?? これが私のコードです...

<?php
if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "#@gmail.com";
    $email_subject = "##";


    function died($error) {
        // your error code can go here   
        echo "<img src=\"../images/errors.found.png\"/>";
        echo "<br /><img src=\"../images/errors.below.png\"/><br /><br />";
        echo $error."<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;               &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<a href='/home/form/contactform.htm'><img src=\"../images/back.png\"/></a>"; 
        die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['guests']) ||
        !isset($_POST['comments'])) {
        died('');       
    }

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; //  required
    $guests = $_POST['guests']; //  required
    $comments = $_POST['comments']; // required

    $error_message = "";

    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= '<img src="../images/fname.valid.png" width="744" height="26" /><br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= '<img src="../images/lname.valid.png" width="744" height="26" /><br />';
  }
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= '<img src="../images/email.vaild.png" width="744" height="26" /><br />';
  }
    $string_exp = "/^[0-9 .'-]+$/";
  if(!preg_match($string_exp,$telephone)) {
    $error_message .= '<img src="../images/phone.valid.png" width="744" height="26" /><br />';
  }  
    $string_exp = "/^[0-9 .'-]+$/";
  if(!preg_match($string_exp,$guests)) {
    $error_message .= '<img src="../images/guests.valid.png" width="744" height="26" /><br />';
  }
  if(strlen($comments) < 0) {
    $error_message .= '<img src="../images/comments.valid.png" width="744" height="26" /><br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

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

    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Number of guests: ".clean_string($guests)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- include your own success html here -->

<br /><br /><br /><br /><br /><br /><br /><img src="../images/email_sent.gif" width="685" height="51" />
<?php
}
?>
4

0 に答える 0