2017-04-11 61 views
0
<?php 

if (isset($_POST["sendMessage"])) { 
    $firstName = trim($_POST['firstName']); 
    $lastName = trim($_POST['lastName']); 
    $email = trim($_POST['email']); 
    $phone = trim($_POST['phone']); 
    $message = trim($_POST['message']); 
    $from = '[email protected]'; 
    $to = '[email protected]'; 
    $subject = '[email protected]'; 
    $txt = 'Prottyasha School'; 
    $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"; 
    //echo "success?"; 


    if (mail($to, $subject, $body, $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; 
} 

?> 

它工作正常,但我想使其驗證。假設有人給出了無效的電話號碼或電子郵件,那麼它會發送無效的郵件或電話號碼。我想讓它充分驗證。任何人都請幫助我。驗證完整聯繫頁面

+0

看看[https://www.tutorialspoint.com/php/php_validation_example.htm] –

+0

它顯示頁面未找到。你會再請檢查一次嗎? – Farjana

+0

請檢查更正的網址 –

回答

0

我不認爲有可能檢查郵件是否成功發送。 mail()返回布爾值true表示郵件已接受發送或發送到本地電子郵件服務。無法知道該電子郵件是否已發送給收件人。