-1

1 つの HTML ページにある 2 つのフォームを PHP コードで処理するにはどうすればよいですか。それを機能させる方法を完全に理解しているかどうかはわかりません。方法を探していましたが、解決策よりも多くのエラーを見つけ続けているようです。

<?php

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    foreach ($_POST as $key => $value) {
        $value = trim($value);

        if (empty($value)) {
            exit("Empty fields are not allowed. Please go back and fill in the form properly.");
        } elseif (preg_match($exploits, $value)) {
            exit("Exploits/malicious scripting attributes aren't allowed.");
        } elseif (preg_match($profanity, $value) || preg_match($spamwords, $value)) {
            exit("That kind of language is not allowed through our form.");
        }

        $_POST[$key] = stripslashes(strip_tags($value));       
    }


    $recipient = "Contact Form <sample@sample.com>";
    $subject = "New Message from Sample name";

    $message = "Received an e-mail through your contact form: \n";
    $message .= "Name: {$_POST['name']} \n";
    $message .= "Address: {$_POST['address']}\r";
    $message .= "City: {$_POST['city']} \r"; 
    $message .= "State: {$_POST['state']} \r";
    $message .= "Zip: {$_POST['zip']} \n";
    $message .= "E-mail: {$_POST['email']} \n";
    $message .= "Phone: {$_POST['phone']} \n";
    $message .= "Message: {$_POST['message']} \n";

    $from = 'Contact Form <contact@sample.com>'; 

 // send email
    $success = mail($recipient,$subject,$message,"From: " . $from);

    if ($success) {
        echo "success";
    } else {
        echo "Sorry, there was an error and your mail was not sent. Please contact me at <a href='#'>Email</a> or call me at <a href=''>Phone number</a>.";
    }
}
?>
4

1 に答える 1