所以我正在使用 sendgrid,它有一些很好的文档。我没有使用 laravel 邮件助手,因为它是用于 smtp 的,我想使用他们的 Web API。
如果最近有人使用过 sendgrid,我现在正在使用他们的示例代码(稍作修改)发送电子邮件。
// using SendGrid's PHP Library
// https://github.com/sendgrid/sendgrid-php
// If you are using Composer (recommended)
require 'vendor/autoload.php';
// If you are not using Composer
// require("path/to/sendgrid-php/sendgrid-php.php");
$view = View::make('emails.tenant')->render();
$from = new SendGrid\Email("Pearlai", "pearlai@pearlai.com");
$subject = "Sending with SendGrid is Fun";
$to = new SendGrid\Email("Daniel Cull", "daniel@pearlai.com");
$content = new SendGrid\Content("text/html", $view);
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$apiKey = env('SENDGRID_API_KEY');
$sg = new \SendGrid($apiKey);
$response = $sg->client->mail()->send()->post($mail);
Log::info($response->statusCode());
Log::info($response->headers());
Log::info($response->body());
我是 PHP 新手,不仅仅是 Laravel :D 我的第一个问题是如何在我的控制器中正确“使用”sendgrid-api 类?就像在包含 Log 门面时一样,我会说“使用 Log;”
我的目标是拥有一段每周运行一次的代码,当它运行时它会收集数据,生成包含数据的电子邮件并将它们发送给收件人。我需要查看 laravel 事件处理程序,对吗?
编辑:单击按钮时发生的错误:
(1/1) FatalThrowableError
Parse error: syntax error, unexpected end of file, expecting function
(T_FUNCTION) or const (T_CONST)
in EmailController.php (line 87)
at Composer\Autoload\includeFile('C:\\Users\\danie\\Documents\\Pearlai\\CRM_Dashboard\\vendor\\composer/../../app\\Http\\Controllers\\Emails\\EmailController.php')
in ClassLoader.php (line 322)
at ClassLoader->loadClass('App\\Http\\Controllers\\Emails\\EmailController')
at spl_autoload_call('App\\Http\\Controllers\\Emails\\EmailController')
at class_exists('App\\Http\\Controllers\\Emails\\EmailController')
in IlluminateRouteCollector.php (line 63)
at IlluminateRouteCollector->getRouteInformation(object(Route))
in IlluminateRouteCollector.php (line 37)
at IlluminateRouteCollector->collect()
in LaravelDebugbar.php (line 769)
at LaravelDebugbar->collect()
in DebugBar.php (line 246)
at DebugBar->getData()
in JavascriptRenderer.php (line 872)
at JavascriptRenderer->render()
in LaravelDebugbar.php (line 805)
at LaravelDebugbar->injectDebugbar(object(Response))
in LaravelDebugbar.php (line 697)
at LaravelDebugbar->modifyResponse(object(Request), object(Response))
in Debugbar.php (line 60)
at Debugbar->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in TrustProxies.php (line 56)
at TrustProxies->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in TransformsRequest.php (line 30)
at TransformsRequest->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in TransformsRequest.php (line 30)
at TransformsRequest->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in ValidatePostSize.php (line 27)
at ValidatePostSize->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in CheckForMaintenanceMode.php (line 46)
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in Pipeline.php (line 102)
at Pipeline->then(object(Closure))
in Kernel.php (line 151)
at Kernel->sendRequestThroughRouter(object(Request))
in Kernel.php (line 116)
at Kernel->handle(object(Request))
in index.php (line 53)
at require_once('C:\\Users\\danie\\Documents\\Pearlai\\CRM_Dashboard\\public\\index.php')
in server.php (line 21)
目前卡在未正确加载 sendgrid 类