-2
PHPコードを使用して簡単な連絡フォームを作成し、フィールドが空の場合やコンテンツフィールドの特定の基準に一致しません。 。。。私は「@」記号が含まれている必要があり、電子メールの入力ボックス(例えばへの標準的な基準を適用している。しかし、すべての正しい基準が一致した場合でも、私のPHPはまだスローし、エラーPHPコンタクトフォームの入力フィールドでエラーが発生しましたが、その理由がわかりません
ここ はコードです:
<?php
if(isset($_POST['email'])){
\t // Here is the email to information
\t $email_to ="[email protected]";
\t $email_subject ="example.co.uk contact form";
\t $email_from ="Website Contact Form";
\t
\t // Error Code
\t
\t function died($error) {
\t \t echo 'Sorry, there is a problem with the form you submitted. ';
\t \t echo 'These errors appear below.<br/><br/>';
\t \t echo $error. '<br/><br/>';
\t \t echo 'Please go back and fix these errors.';
\t \t die();
\t \t }
\t \t
\t // Validation
\t
\t \t if(!isset($_POST['name']) ||
\t \t !isset($_POST['email']) ||
\t \t !isset($_POST['comments'])){
\t \t \t died('All fields must be filled out.');
\t \t \t } \t
\t \t
\t \t $name = $_POST['name'];
\t \t $email = $_POST['email'];
\t \t $comments = $_POST['comments'];
\t \t
\t \t $error_message = "";
\t \t $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]
\t \t {2,4}$/';
\t \t if(!preg_match($email_exp, $email)){
\t \t \t $error_message .= 'The Email Address you entered does not appear to be valid.';
\t \t \t }
\t \t
\t \t $string_exp = "/^[A-Za-z.'-]+$/";
\t \t if (!preg_match($string_exp, $name)){
\t \t \t $error_message .= 'The Name you entered does not appear to be valid.';
\t \t \t }
\t \t if (strlen($comments) < 2){
\t \t \t $error_message .= 'The Comments you entered do not appear to be valid.<br/>';
\t \t \t }
\t \t if (strlen($error_message) > 0){
\t \t \t died($error_message);
\t \t \t }
\t \t \t $email_message = "Form Details Below. \n\n";
\t \t \t
\t \t function clean_string($string){
\t \t $bad = array("content-type", "bcc:", "to:", "cc:", "href");
\t \t return str_replace($bad, "", $string);
\t \t }
\t \t
\t \t $email_message .= "Name:" . clean_string($name) . "\n";
\t \t $email_message .= "Email:" . clean_string($email) . "\n";
\t \t $email_message .= "Comments:" . clean_string($comments) . "\n";
\t \t
\t \t
\t \t // Create Email Headers
\t \t $headers = 'From: ' .$email_from . "\r\n". 'Reply-To:' . $email. "\r\n" .
\t \t 'X-Mailer: PHP/' . phpversion();
\t \t @mail($email_to, $email_subject, $email_message, $headers);
\t \t
?>
<html>
<!-- success message goes here-->
Thank You for contacting us, we will be in touch shortly. <br/>
Please Click <a href="contact.html">here<a/> to go back to the contact page.
</html>
<?php } ?>
それはまだ私のエラーメッセージを与えている理由を誰もが理解していますか?
あなたはどんなエラーがありますか? –
デバッグのために、@mail($ ema)から '@ 'を削除してください。デバッグに役立つエラーが表示されます –
エラーが表示されます.. –