Мой почтовый ReCaptcha не будет работать
Я настраиваю этот сайт для школьного проекта, но мой почтовый ReCaptcha продолжает возвращать HTTP ERROR 500. Может кто-нибудь помочь мне и найти проблему?
Это веб-сайт: http://i385436.hera.fhict.nl/cates/contact.html
Я предполагаю, что ошибка заключается в двух PHP-файлах: contact.php и autoload.php, которые предварительно сделаны и загружены (так как я довольно нуб, когда дело доходит до PHP). Я считаю, что я настроил каждый параметр в файлах, например, получил ключи reCaptcha и т. Д.
Это код для contact.php:
<?php
// require ReCaptcha class
require('autoload.php');
// configure
$from = 'tgdtom@gmail.com';
$sendTo = 'tgdtom@gmail.com';
$subject = 'Bericht via Cates contactformulier';
$fields = array('name' => 'Naam', 'email' => 'Email', 'phone' => 'Tel.nr.', 'message' => 'Bericht'); // array variable name => Text to appear in the email
$okMessage = 'Uw bericht is met succes verzonden, u krijgt zo snel mogelijk reactie!';
$errorMessage = 'Er is iets fout gegaan met het versturen van uw bericht, probeer het later nog eens of neem telefonisch contact op.';
$recaptchaSecret = '6Lf9ZzUUAAAAAL7qstYlXD8pE8LCvpsDWWlvsW5-';
// let's do the sending
try
{
if (!empty($_POST)) {
// validate the ReCaptcha, if something is wrong, we throw an Exception,
// i.e. code stops executing and goes to catch() block
if (!isset($_POST['g-recaptcha-response'])) {
throw new \Exception('ReCaptcha is not set.');
}
// do not forget to enter your secret key in the config above
// from https://www.google.com/recaptcha/admin
$recaptcha = new \ReCaptcha\ReCaptcha($recaptchaSecret, new \ReCaptcha\RequestMethod\CurlPost());
// we validate the ReCaptcha field together with the user's IP address
$response = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$response->isSuccess()) {
throw new \Exception('ReCaptcha was not validated.');
}
// everything went well, we can compose the message, as usually
$emailText = "You have new message from contact form\n=============================\n";
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
$headers = array('Content-Type: text/plain; charset="UTF-8";',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
);
mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
else {
echo $responseArray['message'];
}
И это autoload.php:
<?php
/* An autoloader for ReCaptcha\Foo classes. This should be required()
* by the user before attempting to instantiate any of the ReCaptcha
* classes.
*/
spl_autoload_register(function ($class) {
if (substr($class, 0, 10) !== 'ReCaptcha\\') {
/* If the class does not lie under the "ReCaptcha" namespace,
* then we can exit immediately.
*/
return;
}
/* All of the classes have names like "ReCaptcha\Foo", so we need
* to replace the backslashes with frontslashes if we want the
* name to map directly to a location in the filesystem.
*/
$class = str_replace('\\', '/', $class);
/* First, check under the current directory. It is important that
* we look here first, so that we don't waste time searching for
* test classes in the common case.
*/
$path = dirname(__FILE__).'/'.$class.'.php';
if (is_readable($path)) {
require_once $path;
}
/* If we didn't find what we're looking for already, maybe it's
* a test class?
*/
$path = dirname(__FILE__).'/../tests/'.$class.'.php';
if (is_readable($path)) {
require_once $path;
}
});
Я надеюсь, что вы, ребята / девушки, сможете найти проблемы или найти лучшую альтернативу для меня. Заранее спасибо!