我做了一個簡單的聯繫我們表單,它工作得很好。但是現在,在添加用於發送和接收電子郵件的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),但我確實檢查了大括號並計算了錯誤。現在,當我運行表單時,它顯示空白頁面。 –