Я всего лишь PHP идиот, поэтому я повторно использую код PHP, который работает на другом моем сайте, чтобы получить электронное письмо, когда посетители используют форму HTML. Хотя весь код HTML и PHP выглядит для меня соответствующим образом, отправка формы всегда вызывает errorurl . Я подозреваю, что проблема может быть в recaptcha, так как панель управления recaptcha говорит мне, что она не используется. Может ли кто-нибудь помочь этому журналисту, ставшему невольным разработчиком? Заранее спасибо.
Клаудио
Вот форма HTML:
<form action="contactus.php" method="post" name="contact_form" target="_self" >
<div class="row">
<div class="col-sm"><label for="yourname">Your first name<strong>*</strong></label>
<input autofocus required type="text" id="yourname" class="form-control" accesskey="n" tabindex="1" placeholder="please enter your given name"></div>
<div class="col-sm"><label for="yoursurname">Your family name<strong>*</strong></label>
<input autofocus required type="text" id="yoursurname" class="form-control" accesskey="s" tabindex="2" placeholder="please enter your family name"></div>
<div class="col-sm"><label for="yourmobile">Your mobile<strong>*</strong></label><input required maxlength="10" type="tel" id="yourmobile" class="form-control" accesskey="m" tabindex="3" placeholder="enter your mobile, no spaces or prefix"></div>
</div>
<div class="row">
<div class="col-sm"><label for="youremail">Your email<strong>*</strong></label>
<input required type="email" id="youremail" class="form-control" accesskey="e" tabindex="4" placeholder="please enter your email"></div>
<div class="col-sm">
<label for="yourcompany">Your Company</label>
<input type="text" class="form-control" id="yourcompany" accesskey="c" tabindex="5" placeholder="Your Company">
<small id="emailHelp1" class="form-text text-muted">We'll never share your details with anyone else.</small> </div></div>
<div class="form-group">
<label for="healthfund">Your comments<strong>*</strong></label>
<textarea class="form-control" id="healthfund" rows="5" tabindex="6" placeholder="Write away, no tight limits!"></textarea>
</div>
<div class="form-group"><label for>Please reassure us that you are human... </label><br>
<div class="g-recaptcha" id="recaptcha" data-sitekey="6LfKAcwUAAAAAAzIKAGlduOulkTw5PU7cuFzdUst"></div>
<input class="btn btn-success btn-lg float-right ml-4" name="submit" type="submit" id="submit" tabindex="7" value="OK" /><input class="btn bg-danger btn-lg float-right" name="cancel" type="button" tabindex="8" value="Cancel" onClick="javascript:history.go(-1)"/></div>
</form>
, а это файл PHP:
<?php
$mailto = 'claudioparoli@gmail.com' ;
$subject = "contact" ;
$formurl = "contactus.html" ;
$errorurl = "contacterror.html" ;
$thankyouurl = "contactthankyou.html" ;
$yourname_is_required = 1;
$yoursurname_is_required = 1;
$yourmobile_is_required = 1;
$youremail_is_required = 1;
$yourcompany_is_required = 0;
$comments_is_required = 1;
$uself = 1;
$use_envsender = 0;
$use_sendmailfrom = 0;
$use_webmaster_email_for_from = 0;
$use_utf8 = 1;
$my_recaptcha_private_key = '' ;
// -------------------- END OF CONFIGURABLE SECTION ---------------
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ;
if (!isset( $use_envsender )) { $use_envsender = 0 ; }
if (isset( $use_sendmailfrom ) && $use_sendmailfrom) {
ini_set( 'sendmail_from', $mailto );
}
$envsender = "-f$mailto" ;
$yourname = (isset($_POST['yourname']))? $_POST['yourname'] : $_POST['yourname'] ;
$yoursurname = $_POST['yoursurname'];
$yourmobile = $_POST['yourmobile'] ;
$youremail = $_POST['youremail'] ;
$yourcompany = $_POST['yourcompany'] ;
$comments = $_POST['comments'];
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['youremail'])) {
header( "Location: $formurl" );
exit ;
}
if (($youremail_is_required && (empty($youremail) || !preg_match('/@/', $youremail))) || ($yourname_is_required && empty($yourname)) || ($yoursurname_is_required && empty($yoursurname)) || ($yourmobile_is_required && empty($yourmobile)) || ($yourcompany_is_required && empty($yourcompany)) || ($comments_is_required && empty($comments))) {
header( "Location: $errorurl" );
exit ;
}
if ( preg_match( "/[\r\n]/", $yourname ) || preg_match( "/[\r\n]/", $youremail ) ) {
header( "Location: $errorurl" );
exit ;
}
if (strlen( $my_recaptcha_private_key )) {
require_once( '../../edge/recaptchalib.php' );
$resp = recaptcha_check_answer ( $my_recaptcha_private_key, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] );
if (!$resp->is_valid) {
header( "Location: $errorurl" );
exit ;
}
}
if (empty($youremail)) {
$youremail = $mailto ;
}
$fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ;
if (function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc()) {
$details = stripslashes( $details );
}
$messageproper =
"This message was sent from:\n" .
"$http_referrer\n" .
"-------------------THE SENDER-----------------------\n\n" .
"name of sender: $yourname\n" .
"surname of sender: $yoursurname\n" .
"mobile of sender: $yourmobile\n" .
"email of sender: $youremail\n" .
"company of sender: $yourcompany\n" .
"comments by sender: $comments\n\n" .
"\n\n------------------------------------------\n" ;
$headers =
"From: \"$yourname\" <$youremail>" . $headersep . "Reply-To: \"$yourname\" <$youremail>" . $headersep . "X-Mailer: chfeedback.php 2.15.0" .
$headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;
if ($use_envsender) {
mail($mailto, $subject, $messageproper, $headers, $envsender );
}
else {
mail($mailto, $subject, $messageproper, $headers );
}
header( "Location: $thankyouurl" );
?>