我根据文档输入了代码,我唯一做的就是添加模板。任何人都可以看到什么是错的吗?
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
date_default_timezone_set('EST');
# Include the API
require 'vendor/autoload.php';
require 'lib/SendGrid.php';
require 'html2text.php';
# Instantiate the client.
$sendgrid = new SendGrid('...', '...', array("turn_off_ssl_verification" => true));
$html = $_POST["message"];
$text = convert_html_to_text($html);
$date = date('l, F jS ');
# Make the call to the client.
$email = new SendGrid\Email();
$email
->addTo('...')
# ->addTo('...') uncomment on final script
->setFrom('...')
->setSubject('New reminder for ' . $date)
->setText($text)
->setHtml($html)
->addFilter("templates", "enabled", 1)
->addFilter("templates", "template_id", "a874a34a-a9b7-460b-a5ae-7226e68da0f1")
;
print '<h1>Sent successfully</h1>';
?>
结果:
Fatal error: Class 'SendGrid\Email' not found in /home/[...]/public_html/[...]/sendgrid.php on line 29
答案 0 :(得分:1)
看起来SendGrid\Email
类没有正确自动加载。要手动修复它,您可以添加require 'lib/SendGrid/Email.php';
。
答案 1 :(得分:0)
如果您不使用Composer,只需以zip格式下载并安装该库的最新打包版本。
然后要求包中的库:
require("path/to/sendgrid-php/sendgrid-php.php");
答案 2 :(得分:0)
确保您拥有php 5.8 OR 7.0。我遇到了同样的问题,为了让它起作用,我做了以下工作:
{
"require": {
"sendgrid/sendgrid": "~5.1"
}
}
php composer.phar update
php composer.phar install