发送电子邮件错误无限循环

时间:2017-09-05 09:33:08

标签: php

我有一个没有发送电子邮件的联系表格。它进入无限循环加载,我在控制台中没有任何错误。 看起来代码不能访问sendemail.php类。

联系表格的代码是:

<form class="nobottommargin" id="template-contactform" name="template-contactform" action="include/sendemail.php" method="post">
<div class="form-process"></div>
<div class="col_one_third">
   <label for="template-contactform-name">Nome <small>*</small></label>
   <input type="text" id="template-contactform-name" name="template-contactform-name" value="" class="sm-form-control required" />
</div>
<div class="col_one_third">
   <label for="template-contactform-email">Email <small>*</small></label>
   <input type="email" id="template-contactform-email" name="template-contactform-email" value="" class="required email sm-form-control" />
</div>
<div class="col_one_third col_last">
   <label for="template-contactform-phone">Telefono </label>
   <input type="text" id="template-contactform-phone" name="template-contactform-phone" value="" class="sm-form-control" />
</div>
<div class="clear"></div>
<div class="col_full">
   <label for="template-contactform-subject">Oggetto <small>*</small></label>
   <input type="text" id="template-contactform-subject" name="template-contactform-subject" value="" class="required sm-form-control" />
</div>
<div class="clear"></div>
<div class="col_full">
   <label for="template-contactform-message">Messaggio <small>*</small></label>
   <textarea class="required sm-form-control" id="template-contactform-message" name="template-contactform-message" rows="6" cols="30"></textarea>
</div>
<div class="col_full">
   <button name="submit" type="submit" id="submit-button" tabindex="5" value="Submit" class="button button-3d nomargin">Invia Richiesta</button>
</div></form>

sendemail.php类是如此形成的。看起来下面代码中的提交表单无法访问此代码:

<?php
if(isset($_POST['template-contactform-email'])) {
    $email_to = "info@bs-partners.eu";
    $email_subject = "Richiesta Informazioni dal sito";
    function died($error) {
        echo "Errore. Email <strong>non</strong> inviata. Riprovi più tardi.<br /><br /><strong>Motivo:</strong><br />'";
        echo $error."<br /><br />";
        die();
    }
    if(!isset($_POST['template-contactform-name']) ||
        !isset($_POST['template-contactform-email']) ||
        !isset($_POST['template-contactform-message'])) {
        died('Errore nei dati inseriti');       
    }
    $name = $_POST['template-contactform-name'];
    $email = $_POST['template-contactform-email'];
    $phone = $_POST['template-contactform-phone'];
    $subject = $_POST['template-contactform-subject'];
    $message = $_POST['template-contactform-message']; 
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

  if(!preg_match($email_exp,$email)) {
    $error_message .= 'Email non valida.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$name)) {
    $error_message .= 'Nome non valido.<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 .= "Nome: ".clean_string($name)."\n";
    $email_message .= "Oggetto: ".clean_string($email)."\n";
    $email_message .= "Email: ".clean_string($phone)."\n";
    $email_message .= "Telefono: ".clean_string($subject)."\n";
    $email_message .= "Testo: ".clean_string($message)."\n";
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>
<!-- include your own success html here -->
Il messaggio è stato inviato <strong>correttamente</strong> . Al più presto riceverà una risposta.
<?php
}
?>

感谢大家的支持

0 个答案:

没有答案