嗨,我正在尝试使用php和sendgrid从我的网站发送电子邮件。这是我的php:
<?php
require_once('sendgrid-php/sendgrid-php.php');
$name = $_POST["name"];
$email = $_POST["email"];
$header = $_POST["header"];
$message = $_POST["message"];
try {
$from = new SendGrid\Email(null, $email);
$subject = $header;
$to = new SendGrid\Email(null, "MY EMAIL");
$content = new SendGrid\Content("text/plain", $message);
$mail = new SendGrid\Mail($from, $subject, $to, $content);
$apiKey = 'MY 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";
}
} catch (Exception $e) {
echo $e->errorMessage();
}
echo $response->statusCode();
var_dump($response->headers());
echo $response->body();
我收到此错误; PHP致命错误:未捕获错误:在/home/al8xghxhnuw5/public_html/scripts/index.php:11
中找不到类'SendGrid \ Email'我四处寻找修复程序,但没有任何效果,添加了require sendgrid-php / lib // mail / Email.php无效。
我整天都在努力工作,任何帮助都会很棒