我做了一个简单的联系我们表单,它工作得很好。但是现在,在添加用于发送和接收电子邮件的mailgun脚本之后,它只显示了一个空白页面。在提交php联系表格时收到空白页面没有错误
脚本:
<?php
require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mailgun = new Mailgun('key-41616099541fe1b0187e7cd970127240', new \Http\Adapter\Guzzle6\Client());
$mgClient = new Mailgun('key-41616099');
$domain = "sandbox614b.mailgun.org";
$from = 'Demo contact form <[email protected] >';
$to = 'Demo contact form <[email protected]>';
$name = $_POST['name'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$fields = array('name' => 'Name', 'email' => 'Email', 'phone' => 'Phone', 'subject' => 'Subject', 'message' => 'Message');
$okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!';
$errorMessage = 'There was an error while submitting the form. Please try again later';
// if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
try
{
if(count($_POST) == 0) throw new \Exception('Form is empty');
$content = "You have a new message from your contact form";
foreach ($_POST as $key => $value)
{
if (isset($fields[$key]))
{
$content .= "$fields[$key]: $value\n";
//recaptcha-response
$recaptcha_secret = "6LfK7ygUAAAAAIYzE6mbqdxbmuroi4gJWqdIpmBu";
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);
$response = json_decode($response, true);
# Make the call to the client.
$result = $mgClient->sendMessage("$domain",
array('from' => 'Mailgun Sandbox <[email protected]>',
'to' => 'Nami <[email protected]>',
'subject' => 'Hello Nami',
'text' => 'Congratulations Nami, you just sent an email with Mailgun! You are truly awesome! '));
echo "Form Submit Successfully.";
} else {
echo "You are a robot";
}
}
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
?>
我应该怎么做来可能做错了什么?
检查您的错误日志中是否有任何内容 – Kai
我收到的最后一个错误日志是这样的:语法错误,第68行中意外的'else'(T_ELSE),但我确实检查了大括号并计算了错误。现在,当我运行表单时,它显示空白页面。 –