【发布时间】:2018-07-23 11:19:43
【问题描述】:
实际上,我正在开发 Core PHP,现在我正在创建带有邮件功能的 google recaptcha 联系我们页面,所以当我应用 google recaptcha 代码时会显示如下问题:
警告:file_get_contents(): https:// 包装器在 通过 allow_url_fopen=0 配置服务器
请帮助任何人。
我的代码是:
<?php
ini_set('display_errors',1); error_reporting(E_ALL);
if(isset($_POST['submit'])){
$userIP = $_SERVER["REMOTE_ADDR"];
$recaptchaResponse = $_POST['g-recaptcha-response'];
$secretKey = 'xxx';
$request = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secretKey}&response={$recaptchaResponse}&remoteip={$userIP}");
if(!strstr($request, "true")){
echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong>There was a problem with the Captcha, you lied to us! you are a robot! or you just didnt click it :)</div>';
}
else{
// echo "WORKS";
if(isset($_POST['submit']))
{
$message=
'Full Name: '.$_POST['fullname'].'<br />
Subject: '.$_POST['subject'].'<br />
Phone: '.$_POST['phone'].'<br />
Email: '.$_POST['emailid'].'<br />
Comments: '.$_POST['comments'].'
';
require "PHPMailer-master/class.phpmailer.php"; //include phpmailer class
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "ssl"; // Connect using a TLS connection
$mail->Host = "smtp.gmail.com"; //Gmail SMTP server address
$mail->Port = 465; //Gmail SMTP port
$mail->Encoding = '7bit';
// Authentication
$mail->Username = $senderEmail; // Your full Gmail address
$mail->Password = $senderPassword; // Your Gmail password
// Compose
$mail->SetFrom($_POST['emailid'], $_POST['fullname']);
$mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
$mail->Subject = "New Contact Form Enquiry"; // Subject (which isn't required)
$mail->MsgHTML($message);
// Send To
$mail->AddAddress($receiverEmail, $receiverName); // Where to send it - Recipient
$result = $mail->Send(); // Send!
$message = $result ? '<div class="alert alert-success" role="alert"><strong>Success!</strong>Message Sent Successfully!</div>' : '<div class="alert alert-danger" role="alert"><strong>Error!</strong>There was a problem delivering the message.</div>';
unset($mail);
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PHPMailer Contact Form</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<div class="contactform">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><a href="">Contact Form</a></h3>
</div>
<div class="panel-body">
<form name="form1" id="form1" action="" method="post">
<fieldset>
<input type="text" class="form-control" name="fullname" placeholder="Full Name" />
<br />
<input type="text" class="form-control" name="subject" placeholder="Subject" />
<br />
<input type="text" class="form-control" name="phone" placeholder="Phone" />
<br />
<input type="email" class="form-control" name="emailid" placeholder="Email" />
<br />
<textarea rows="4" class="form-control" cols="20" name="comments" placeholder="Comments"></textarea>
<br />
<div class="g-recaptcha" data-sitekey="6Ldgy2QUAAAAAPRkDWHgLJ81rRVdca0V1Qq2t8mA12"></div>
<input type="submit" class="btn btn-lg btn-success button"name="submit" value="Send Message" />
</fieldset>
</form>
<p><?php if(!empty($message)) echo $message; ?></p>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</body>
</html>
【问题讨论】:
-
嗨,请注意,这里只有问题你能解释一下 $request = file_get_contents("google.com/recaptcha/api/siteverify?secret={$secretKey}&response={$recaptchaResponse}&remoteip={$userIP}");