0
私はStackoverflowを初めて使用しています。PHPフォームのHTML出力
HTMLテンプレートとして保存する必要があるPHPフォームがあります。成功メッセージはこれでうまくいきます。しかし、電子メールで送られたメッセージはそれをしません。ここに私のコード例があります。フォームは、HTML出力を除いてうまく動作します。私はそれが動作するかどうかを確認するためにタグを入れますが、タグは変換されません。
ご協力いただければ幸いです。
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = ($_POST['email']);
$email_subject = "Dear ".($_POST['first_name']). ", someone you know sent you this email.";
function died($error) {
// your error code can go here
echo "<h4>We are very sorry, but you left a field blank or incorrect. </h4>";
echo "Maybe you need to be slapped.<br /><br />";
echo $error."<br /><br />";
echo "Please press the back button to resend redo.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) // ||!isset($_POST['last_name'])
||!isset($_POST['email'])
//||!isset($_POST['telephone'])
//||!isset($_POST['comments'])
) {
died('We are very sorry, but left a field blank or incorrect.');
}
$first_name = $_POST['first_name']; // required
// $last_name = $_POST['last_name']; // required
$email_from = "[email protected]"; // required
// $telephone = $_POST['telephone']; // not required
// $comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
// if(!preg_match($string_exp,$last_name)) {
// $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
// }
// if(strlen($comments) < 2) {
// $error_message .= 'The Comments you entered do not appear to be valid.<br />';
// }
if(strlen($error_message) > 0) {
died($error_message);
}
// Set the Headers for HTML E-mail
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// email message sent to the person getting slapped
$email_message = "Someone has just sent you an email.\n\n";
function clean_string($string) {
$headers = "Content-Type: text/html; charset=iso-8859-1\n";
$email_message = " This is a test <strong> of the HTML </strong>";
}
$email_message = " This is a test <strong> of the HTML </strong>";
// $email_message .= "First Name: ".clean_string($first_name)."\n";
// $email_message .= "Last Name: ".clean_string($last_name)."\n";
// $email_message .= "Email: ".clean_string($email_from)."\n";
// $email_message .= "Telephone: ".clean_string($telephone)."\n";
// $email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'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 sending your <strong>email</strong>. <br />
Please press the back button
<?php
}
?>
あなたの答えはありがとうKevin。私はそれを試して、出力は "これはののテストです"と出ています。それは言葉を大胆にしていません。助言がありますか? –