私は自分のニーズに合わせて編集した簡単な電子メールフォームを持っていますが、すべてうまく機能しています.....ただし....
フォームのテキスト フィールドには既に単語が含まれているため、ユーザーは何を入力すればよいかがわかります。
これらの言葉は
名前 住所 郵便番号 電話 メッセージ
ユーザーが「空のメール」を送信しようとすると....フォームは、メールチェックと電話チェックのためにそれを拒否します (メールには @ + . が必要で、電話には数字とスペースのみが必要です!)
私がやろうとしているのは、「名前」「住所」「郵便番号」「電話」という単語を禁止することです.....
メッセージは私には関係ありません!
ここに私が使用しているスクリプトがあります:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "me@me.com";
$email_subject = "My Email";
function died($error) {
// your error code can go here
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();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['address1']) ||
!isset($_POST['postcode']) ||
!isset($_POST['phone']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$address1 = $_POST['address1']; // required
$postcode = $_POST['postcode']; // required
$phone = $_POST['phone']; // required
$message = $_POST['message']; // not required
$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$address_exp = "/^[A-Za-z 0-9 .',-]+$/";
if(!preg_match($address_exp,$address1)) {
$error_message .= 'The Address you entered does not appear to be valid.<br />';
}
$postcode_exp = "/^[A-Za-z 0-9 .',-]+$/";
if(!preg_match($postcode_exp,$postcode)) {
$error_message .= 'The Postcode you entered does not appear to be valid.<br />';
}
$phone_exp = "/^[0-9 ]+$/";
if(!preg_match($phone_exp,$phone)) {
$error_message .= 'The Phone number you entered does 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($name)."\n";
$email_message .= "email: ".clean_string($email)."\n";
$email_message .= "address1: ".clean_string($address1)."\n";
$email_message .= "postcode: ".clean_string($postcode)."\n";
$email_message .= "phone: ".clean_string($phone)."\n";
$email_message .= "message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$whofrom=$_POST["email"];
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
やり方がわからないので教えていただけると助かります!