繁体   English   中英

SendGrid给出致命错误

[英]SendGrid gives fatal error

我根据文档放入了代码,唯一要做的就是添加模板。 谁能看到什么问题?

    <?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

看起来SendGrid\\Email类未正确自动加载。 要手动修复它,您可以添加require 'lib/SendGrid/Email.php';

如果您不使用Composer,只需下载并安装该库的最新打包版本作为zip。

然后从包中要求库:

require("path/to/sendgrid-php/sendgrid-php.php");

确保您拥有php 5.8或7.0。 我遇到了同样的问题,请执行以下操作使其生效:

  1. 更新了composer.json
{
    "require": {
        "sendgrid/sendgrid": "~5.1"
    }
}
  1. php composer.phar更新

  2. php composer.phar安装

祝好运。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM