Php 联系方式-未捕获错误:Class';SendGrid\Email';找不到
我收到以下PHP错误“未捕获错误:类”SendGrid\Email“未找到”,我完全不知道为什么。文件路径是100%正确的,我看不出代码不工作的直接原因 我知道PHP有点像雷区,所以如果有任何PHP专家可以帮助解决这个问题,那就太棒了Php 联系方式-未捕获错误:Class';SendGrid\Email';找不到,php,Php,我收到以下PHP错误“未捕获错误:类”SendGrid\Email“未找到”,我完全不知道为什么。文件路径是100%正确的,我看不出代码不工作的直接原因 我知道PHP有点像雷区,所以如果有任何PHP专家可以帮助解决这个问题,那就太棒了 require_once("sendgrid-php/sendgrid-php.php"); $from = new SendGrid\Email(null, "test@test.com"); $subject = "Email from Website";
require_once("sendgrid-php/sendgrid-php.php");
$from = new SendGrid\Email(null, "test@test.com");
$subject = "Email from Website";
$to = new SendGrid\Email(null, "test@test.com");
$message = <<<EMAILBODY
Name: {$_POST['name']}
Email: {$_POST['email']}
subject: {$_POST['subject']}
phone: {$_POST['phone']}
company: {$_POST['company']}
Message: {$_POST['message']}
EMAILBODY;
$content = new SendGrid\Content("text/plain", $message);
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$apiKey = 'MYAPIKEY'; // Your API key
$sg = new \SendGrid($apiKey);
$response = $sg->client->mail()->send()->post($mail);
if($response->statusCode() == 202){
echo "Email sent successfully";
}else{
echo "Email could not be sent";
}
require_once(“sendgrid php/sendgrid php.php”);
$from=new SendGrid\Email(空,“test@test.com");
$subject=“来自网站的电子邮件”;
$to=新建SendGrid\Email(空,“test@test.com");
$message=send()->post($mail);
如果($response->statusCode()==202){
回显“电子邮件发送成功”;
}否则{
echo“无法发送电子邮件”;
}
在此初始行中修改幻灯片
需要_一次(“sendgrid/sendgrid.php”);
i、 e从目录和文件名中删除“-php”。您的代码与他们的php api示例、V2版本和V3版本的api看起来都不一样……我必须诚实地说,我实际上使用了一个代码片段,因为我一直在用它撞砖墙,这似乎是一个很好的解决方案。PHP绝对不是我的强项,因此如果您能就如何正确实现这一点提供任何建议,我们将不胜感激。您应该从他们为您使用的api版本提供的文档开始: