2016-11-15 17 views
1

に送信されません私はこれに間違っている場所を誰かが私を助けることができますか?フォームは「送信」をクリックするとPHPコードに移動します。私は何時間もそれを混乱させてきたし、私がやっていることは非常にシンプルなことをやっていると思っている。これから少し離れて渦に戻ります。しかし、その間に誰かが私を助けることができるなら、私に知らせてください。ここで電子メールは連絡フォーム送信(PHP)

はフランツで指摘したようにここではHTML

<div class="container"> 
 
    <div class="row form-container"> 
 

 
    <div class="col-md-12 contact-form"> 
 
     <h3 style="text-align:center">Rather have us contact you? No problem!</h3> 
 
     <h4 style="text-align:center">Just fill out this form.</h4> 
 
     <form name="contactform" method="post" action="send_form_email.php"> 
 
     <div class="form-group"> 
 
      <input type="text" class="form-control" id="name" name="name" placeholder="Your Name..." value="" required> 
 
     </div> 
 
     <div class="form-group"> 
 
      <input type="text" class="form-control" id="email" name="email" placeholder="Your email..." value="" required> 
 
     </div> 
 
     <div class="form-group"> 
 
      <input type="text" class="form-control" id="phone" name="phone" placeholder="Your phone..." value=""> 
 
     </div> 
 
     <div class="form-group"> 
 
      <textarea class="form-control" rows="4" name="message" placeholder="Your message..."></textarea> 
 
     </div> 
 
     <div class="form-group"> 
 
      <button type="submit formnovalidate" name="submit" value="Submit" class="btn btn-default"><i class="fa fa-paper-plane fa-fw"></i> Send</button> 
 
     </div> 
 
     </form> 
 
    </div> 
 
    </div> 
 
</div>

は間違いエラー抑圧(@記号)を削除し、PHP

<?php 

if(isset($_POST['email'])) { 





$email_to = "[email protected]"; 

$email_subject = "Contact from Hebert Counseling"; 





function died($error) { 



    echo "We are very sorry, but there were error(s) found with the  form you submitted. "; 

    echo "These errors appear below.<br /><br />"; 

    echo $error."<br /><br />"; 

    echo "Please go back and fix these errors.<br /><br />"; 

    die(); 
} 



if(!isset($_POST['name']) || 

    !isset($_POST['email']) || 

    !isset($_POST['phone']) || 

    !isset($_POST['message'])) { 

    died('We are sorry, but there appears to be a problem with the form you submitted.'); 

} 



$first_name = $_POST['name']; // required 

$email_from = $_POST['email']; // required 

$telephone = $_POST['phone']; // not required 

$comments = $_POST['message']; // not required 



$error_message = ""; 

$email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 

if(!preg_match($email_exp,$email_from)) { 

$error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 

} 

$string_exp = "/^[A-Za-z .'-]+$/"; 

if(!preg_match($string_exp,$name)) { 

$error_message .= 'The name you entered does not appear to be valid.<br />'; 

} 

if(strlen($message) < 2) { 

$error_message .= 'The message you entered do not appear to be valid. <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 .= "Name: ".clean_string($first_name)."\n"; 

$email_message .= "Email: ".clean_string($email_from)."\n"; 

$email_message .= "Phone: ".clean_string($telephone)."\n"; 

$email_message .= "Message: ".clean_string($comments)."\n"; 





// 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); 

?> 





Thank you for reaching out! We will be in touch with you very soon! 



<?php 

} 

?> 
+0

最初のステップは、 'mail'関数のエラーを' @ 'で抑止することではありません。 2番目のステップは、あなたのPHPがSMTPサーバで完全に設定されていることを確認することで、 'mail'関数が実際に動作するようにすることです。 –

答えて

0

ですmail()機能の前に。次に、現在表示されていない警告とエラーが表示され、問題を修正できます。

あなたは、任意の電子メールが実際にたmail.logパスでphp.iniの設定によって送信されたかどうかを確認することができます

; The path to a log file that will log all mail() calls. Log entries include 
; the full path of the script, line number, To address and headers. 
mail.log = "C:\xampp\mail.log" 

をあなたはまた、にすべての電子メールをリダイレクトすることができます実際に送信する代わりにファイルを送信してください。 WindowsのXAMPPには、mailtodisk.exeというスクリプトがあります。 php.iniで設定してください:

sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe" 

C:\xampp\mailoutputフォルダーに送信された電子メールがあります。

変更後にサーバーを再起動することを忘れないでください。

関連する問題