「POSTできません/send_form_email.php」というエラーが表示され、その理由がわかりません。ファイルは同じディレクトリにあります。これらは、サイト上の唯一の2つのHTMLファイルまたはPHPファイルです。ここで"POST/send_form_email.phpエラー"の連絡フォームで
<form id="contactform" action="send_form_email.php" method="post">
<div class="form-group">
<label for="firstname">First Name</label>
<input type="text" class="form-control placeholder="First Name" required>
</div>
<div class="form-group">
<label for="lastname">Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" placeholder="Email" required>
</div>
<div class="form-group">
<label for="subject">Phone</label>
<input type="text" class="form-control" placeholder="Phone" required>
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea id="message" rows="3" class="form-control"></textarea>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button name="submit" type="submit" class="btn btn-primary" id="contact-submit">Submit</button>
</div>
</form>
は、それがリンクしているPHPファイルです。私はファイル名をダブルチェックしました。変更を確実にするためにキャッシュをクリアしました。
<?php
if(isset($_POST['email'])) {
// Sent where the email goes here
$email_to = "[email protected]";
$email_subject = "Message from Patient";
function died($error) {
// 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['firstname']) ||
!isset($_POST['lastname']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$firstname = $_POST['firstname']; // required
$lastname = $_POST['lastname']; // required
$email = $_POST['email']; // required
$phone = $_POST['telephone']; // not required
$message = $_POST['message']; // 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);
}
$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 .= "First Name: ".clean_string($firstname)."\n";
$email_message .= "Last Name: ".clean_string($lastname)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Telephone: ".clean_string($phone)."\n";
$email_message .= "Comments: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\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
}
エラー全体を投稿できますか?どのウェブサーバーを使用していますか?何がエラーを投げる? – OptimusCrime
localhostとノードサーバー。 –
エラーがあれば、ブラウザから直接send_form_email.phpにアクセスできますか? – BlackBurn027