2017-04-10 10 views
1
 <?php 
      if (isset($_POST["sendMessage"])) { 
      $firstName = $_POST['firstName']; 
      $lastName = $_POST['last-name']; 
      $email = $_POST['email']; 
      $phone = $_POST['phone']; 
      $message = $_POST['message']; 
      $from= '[email protected]'; 
      $to = '[email protected]'; 
      $subject = 'Message from Contact Demo '; 
      $txt= 'demo'; 
      $headers = "From: [email protected]" . "\r\n" . 
     "CC: [email protected]"; 
     $body = "From: First-Name: $firstName\n Last-Name: $lastName\n      

     E-Mail: $email\n Phone: $phone\n Message: $message"; 
         $errFirstName='';$errLastName='';$errEmail='';$errPhone='';$errMessage=''; 



// If there are no errors, send the email 

     if (mail ($to, $subject,$txt,$headers)) { 
      $result='<div class="alert alert-success">Thank You! I will be in touch</div>'; 
     } else { 
      $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>'; 
     } 
    } 

?> 

私はメールの検証をしようとしていますが、成功しないメッセージやエラーメッセージを出すテキストはありません。何も表示されません。私は自分の責任を理解できません。助けてください。PHPでの電子メールの検証?

+2

ここでメールの確認コードはありませんでしたか? –

+0

結果やエラーがある場合はそれを指定できますか? –

+0

あなたはドイツ語ですか?あなたは英語で "will"という言葉の意味をgoogleする必要があります。それに加えて、変数名... 'firstName'と' last-name'でもっと一定にしてみてください。悪い習慣です。また、あなたの質問を編集し、あなたの電子メールのアドレスを削除し、いくつかのランダムなものと置き換えることができます...それは良いアイデアは、公共のボードにあなたの電子メールアドレスを投稿するとは思わない。また、あなたは '$ errFirstName = ''; $ errLastName = '';'で達成しようとしているのですか? – Twinfriends

答えて

0

ただ、PHPマニュアルからデフォルトの関数を使用します。

<?php 
    $email_a = '[email protected]'; 
    $email_b = 'bogus'; 

    if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) { 
     echo "This ($email_a) email address is considered valid.\n"; 
    } 
    if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) { 
     echo "This ($email_b) email address is considered valid.\n"; 
    } else { 
    echo "This ($email_b) email address is considered invalid.\n"; 
    } 
?> 
0

まずあなたが次にこのPHP関数

$email = test_input($_POST["email"]); 
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { 
    $emailErr = "Invalid email format"; 
} 

を使用してメールが有効である確認する必要がある場合は、そのエラーエルス

を与えない有効な
if (mail ($to, $subject,$txt,$headers)) { 
      $result='<div class="alert alert-success">Thank You! I will be in touch</div>'; 
     } else { 
      $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>'; 
     } 

試してみてください。

1

ライブサーバーでこのコードを試してください

$firstName = "sunny"; 
    $lastName = "khatri"; 
    $email = '******@gmail.com'; 
    $phone = '********'; 
    $message ='Hello this is test'; 
    $from= '*****@gmail.com'; 
    $to = '***@gmail.com'; 
    $subject = 'Message from Contact Demo '; 
    $txt= 'demo'; 
    $headers = "From: ******@*****.com" . "\r\n" . 
    "CC: ********@live.in"; 
    $body = "From: First-Name: $firstName\n Last-Name: $lastName\n      

    E-Mail: $email\n Phone: $phone\n Message: $message"; 
       $errFirstName='';$errLastName='';$errEmail='';$errPhone='';$errMessage=''; 

    // If there are no errors, send the email 

    if (mail ($to, $subject,$txt,$headers)) { 
      $result='<div class="alert alert-success">Thank You! I will be in touch</div>'; 
    } else { 
     $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>'; 
    } 
    echo $result; 
関連する問題