メールが正しくても送信時に「無効なメール」が表示されます。私はこのコードに疑念を抱いています。誰かが一目見てもらえますか?連絡フォームに無効なメールが送信されました
はここで(、.jsファイルを呼び出しているcontact.php、同じである)ここでemail.phpだHTML
<form id="contact-form" action="email.php" method="post" class="clearfix">
<div class="contact-box-hide">
<div class="col-sm-6">
<input type="text" class="form-control" id="first_name" name="first_name" required placeholder="Navn">
<span class="first-name-error"></span>
</div>
<div class="col-sm-6">
<input type="text" class="form-control" id="last_name" name="last_name" required placeholder="Efternavn">
<span class="last-name-error"></span>
</div>
<div class="col-sm-6">
<input type="email" class="form-control" id="email" name="contact_email" required placeholder="Email">
<span class="contact-email-error"></span>
</div>
<div class="col-sm-6">
<input type="text" class="form-control" id="subject" name="contact_subject" required placeholder="Hvor skal oplægget afholdes?">
<span class="contact-subject-error"></span>
</div>
<!--<div class="col-sm-6">
<label class=".radio-inline">
<input type="radio" class="form-control" id="choice" name="options" required placeholder="Emne">
<span class="contact-subject-error"></span>Option 1
</label>
<label class=".radio-inline" style="border-left: 0px;" >
<input type="radio" class="form-control" id="choice" name="options" required placeholder="Emne">
<span class="contact-subject-error"></span>Option 2
</label>
</div>
-->
<!--<div class="col-sm-20">
<input type="radio" class="form-control" id="contact_type" name="nummer 1" checked>
<span class="contact-x-error"></span>
</div>
<div class="col-sm-20">
<input type="radio" class="form-control" id="contact_type" name="nummer 1" checked>
<span class="contact-x-error"></span>
</div>
-->
<div class="col-sm-10">
<textarea class="form-control" rows="5" id="message" name="message" required placeholder="Besked"></textarea>
<span class="contact-message-error"></span>
</div>
<div class="col-sm-2">
<button id="contact-submit" class="btn custom-btn col-xs-12" type="submit" name="submit"><a href=""></a><i class="fa fa-angle-right"></i></button>
<span id="contact-loading" class="btn custom-btn col-xs-12"> <i class="fa fa-refresh fa-spin"></i> </span>
</div>
</div><!-- /.contact-box-hide -->
<div class="contact-message"></div>
</form>
です:
ここ<?php
if($_REQUEST['first_name'] == '' || $_REQUEST['contact_email'] == '' || $_REQUEST['message'] == ''):
return "error";
endif;
if (filter_var($_REQUEST['contact_email'], FILTER_VALIDATE_EMAIL)):
$subject = 'Fra Kriger til Kaemper - kontaktformular'; // Subject of your email
// Receiver email address
$to = '[email protected]'; //Change the email address by yours
// prepare header
$header = 'From: '. $_REQUEST['first_name'] . " " .$_REQUEST['last_name'] . ' <'. $_REQUEST['contact_email'] .'>'. "\r\n";
$header .= 'Reply-To: '. $_REQUEST['first_name'] . " " .$_REQUEST['last_name'] . ' <'. $_REQUEST['contact_email'] .'>'. "\r\n";
// $header .= 'Cc: ' . '[email protected]' . "\r\n";
// $header .= 'Bcc: ' . '[email protected]' . "\r\n";
$header .= 'X-Mailer: PHP/' . phpversion();
$message .= 'Name: ' . $_REQUEST['first_name'] . " " .$_REQUEST['last_name'] . "\n";
$message .= 'Email: ' . $_REQUEST['contact_email'] . "\n";
$message .= 'Subject: ' . $_REQUEST['contact_subject'] . "\n";
$message .= 'Message: '. $_REQUEST['message'];
// Send contact information
$mail = mail($to, $subject , $message, $header);
echo 'sent';
else:
return "error";
endif;
?>
があるの.js:
$('#contact-submit').click(function() {
$('.first-name-error, .last-name-error, .contact-email-error, .contact-subject-error, .contact-message-error').hide();
var first_nameVal = $('input[name=first_name]').val();
var last_nameVal = $('input[name=last_name]').val();
var emailReg = /^(([^<>()[\]\\.,;:\[email protected]\"]+(\.[^<>()[\]\\.,;:\[email protected]\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/igm;
var emailVal = $('#contact_email').val();
var contact_subjectVal = $('input[name=contact_subject]').val();
var messageVal = $('textarea[name=message]').val();
//validate
if (first_nameVal == '' || first_nameVal == 'First Name *') {
$('.first-name-error').html('<i class="fa fa-exclamation"></i> Vi har brug for dit fornavn.').fadeIn();
return false;
}
if (last_nameVal == '' || last_nameVal == 'Last Name *') {
$('.last-name-error').html('<i class="fa fa-exclamation"></i> Vi har brug for dit efternavn.').fadeIn();
return false;
}
if (emailVal == "" || emailVal == "Email Address *") {
$('.contact-email-error').html('<i class="fa fa-exclamation"></i> Vi har brug for din mailadresse.').fadeIn();
return false;
} else if (!emailReg.test(emailVal)) {
$('.contact-email-error').html('<i class="fa fa-exclamation"></i> Ugyldig mailadresse.').fadeIn();
return false;
}
if (contact_subjectVal == '' || contact_subjectVal == 'Subject *') {
$('.contact-subject-error').html('<i class="fa fa-exclamation"></i> Subject is required.').fadeIn();
return false;
}
if (messageVal == '' || messageVal == 'Message *') {
$('.contact-message-error').html('<i class="fa fa-exclamation"></i> Skriv venligst en henvendelse.').fadeIn();
return false;
}
var data_string = $('.contact-form').serialize();
$('#contact-submit').hide();
$('#contact-loading').fadeIn();
$('.contact-error-field').fadeOut();
$.ajax({
type: "POST",
url: "php/contact.php",
data: data_string,
//success
success: function (data) {
$('.contact-box-hide').slideUp();
$('.contact-message').html('<i class="fa fa-check contact-success"></i><div>Your message has been sent.</div>').fadeIn();
},
error: function (data) {
$('.btn-contact-container').hide();
$('.contact-message').html('<i class="fa fa-exclamation contact-error"></i><div>Something went wrong, please try again later.</div>').fadeIn();
}
}) //end ajax call
return false;
});
何かを残しておけば教えてください。私はすぐにそれを提供します!あなたの電子メールフィールドで
動作しないメールを共有できますか? – Ygalbel
私はいくつか試しました。なし。 – Rift