PHP-简单SendGrid致命错误:Class';SendGrid\Email';找不到
我正在尝试使用php sendgrid从联系人表单发送电子邮件。我只需要最简单的实现,并遵循以下基本步骤: 这是我的密码:PHP-简单SendGrid致命错误:Class';SendGrid\Email';找不到,php,sendgrid,Php,Sendgrid,我正在尝试使用php sendgrid从联系人表单发送电子邮件。我只需要最简单的实现,并遵循以下基本步骤: 这是我的密码: require_once 'sendgrid-php/lib/SendGrid.php'; require_once 'unirest-php/lib/Unirest.php'; function spamcheck($field) { $field = filter_var($field, FILTER_SANITIZE_EMAIL); if (fil
require_once 'sendgrid-php/lib/SendGrid.php';
require_once 'unirest-php/lib/Unirest.php';
function spamcheck($field) {
$field = filter_var($field, FILTER_SANITIZE_EMAIL);
if (filter_var($field, FILTER_VALIDATE_EMAIL)) {
return TRUE;
} else {
return FALSE;
}
}
if (isset($_REQUEST['email'])) {
$mailcheck = spamcheck($_REQUEST['email']);
if ($mailcheck == FALSE) {
echo "Invalid Input";
} else {
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$company = $_REQUEST['company'];
$message = $_REQUEST['message'];
$subject = "This is the subject";
$recipient = "test@email.com"; // Not the real value
$username = 'test'; // Not the real value
$password = '1234'; // Not the real value
$sendgrid = new SendGrid($username, $password);
$mail = new SendGrid\Email();
$body = "Name: " . $name . "\n" .
"Company: " . $company . "\n" .
"Message: " . $message;
$mail->addTo($recipient)->
setFrom($email)->
setSubject($subject)->
setText($message);
$sendgrid->smtp->send($mail);
echo 'SUCCESS';
}
} else {
echo "Fail";
}
我得到一个错误:
<br />
<b>Fatal error</b>: Class 'SendGrid\Email' not found in <b>/usr/local/www/vhosts/.../intl/mail.php</b> on line <b>27</b><br />
<br />
<b>Warning</b>: require_once(swift_required.php): failed to open stream: No such file or directory in <b>/usr/local/www/vhosts/.../intl/sendgrid- php/lib/SendGrid/Smtp.php</b> on line <b>25</b><br />
<br />
<b>Fatal error</b>: require_once(): Failed opening required 'swift_required.php' (include_path='.:/usr/local/share/pear') in <b>/usr/local/www/vhosts/.../intl/sendgrid- php/lib/SendGrid/Smtp.php</b> on line <b>25</b><br />
我得到这个错误:
<br />
<b>Fatal error</b>: Class 'SendGrid\Email' not found in <b>/usr/local/www/vhosts/.../intl/mail.php</b> on line <b>27</b><br />
<br />
<b>Warning</b>: require_once(swift_required.php): failed to open stream: No such file or directory in <b>/usr/local/www/vhosts/.../intl/sendgrid- php/lib/SendGrid/Smtp.php</b> on line <b>25</b><br />
<br />
<b>Fatal error</b>: require_once(): Failed opening required 'swift_required.php' (include_path='.:/usr/local/share/pear') in <b>/usr/local/www/vhosts/.../intl/sendgrid- php/lib/SendGrid/Smtp.php</b> on line <b>25</b><br />
警告:require_once(swift_required.php):无法打开流:第25行的/usr/local/www/vhosts/../intl/sendgrid-php/lib/sendgrid/Smtp.php中没有此类文件或目录
致命错误:require_once():在/usr/local/www/vhosts/../intl/sendgrid-php/lib/sendgrid/Smtp.php第25行打开所需的'swift_required.php'(include_path='.:/usr/local share/pear')失败
^基于这一点,我不会使用swift mailer,所以它可能没有关联
我错过了什么
*PHP版本5.4.21
*SendGrid版本1.1.6因为您使用的是SMTP发送方法:
$sendgrid->smtp->send($mail);
您需要安装swiftmailer。有关说明如下:
您的另一个选择是使用web发送,这实际上是我们现在在SendGrid上推荐的。它比聊天的SMTP协议快
$sendgrid->web->send($mail);
由于您使用的是SMTP发送方法:
$sendgrid->smtp->send($mail);
您需要安装swiftmailer。有关说明如下:
您的另一个选择是使用web发送,这实际上是我们现在在SendGrid上推荐的。它比聊天的SMTP协议快
$sendgrid->web->send($mail);
我没有安装swiftmailer,但我安装了smtpapi php和unirest php 我的测试代码如下所示:
require_once ('../includes/sendgrid-php/lib/SendGrid.php');
require_once ('../includes/smtpapi-php/lib/Smtpapi.php');
require_once ('../includes/unirest-php/lib/Unirest.php');
SendGrid::register_autoloader();
Smtpapi::register_autoloader();
$sendgrid = new SendGrid('user', 'pass');
$email = new SendGrid\Email();
$email->addTo( $to)->
setFrom($from)->
setSubject($subject)->
setText('Test')->
setHtml($html);
$x = $sendgrid->send($email);
var_dump($x );
它在PHP5.4上运行我没有安装swiftmailer,但我安装了smtpapi php和unirest php 我的测试代码如下所示:
require_once ('../includes/sendgrid-php/lib/SendGrid.php');
require_once ('../includes/smtpapi-php/lib/Smtpapi.php');
require_once ('../includes/unirest-php/lib/Unirest.php');
SendGrid::register_autoloader();
Smtpapi::register_autoloader();
$sendgrid = new SendGrid('user', 'pass');
$email = new SendGrid\Email();
$email->addTo( $to)->
setFrom($from)->
setSubject($subject)->
setText('Test')->
setHtml($html);
$x = $sendgrid->send($email);
var_dump($x );
它在PHP5.4上工作PHPU使用的是什么版本?需要什么版本的SendGrid库?抱歉。我现在包括了这些版本。请在
require_once'/path/to/unirest-php/lib/unirest.php'之前尝试设置代码>-在示例中,出现了“对不起,仍然不工作”和相同的错误。SendGrid::register_autoloader()代码>你把这个放在哪里?你用的是什么版本的PHP?需要什么版本的SendGrid库?抱歉。我现在包括了这些版本。请在require_once'/path/to/unirest-php/lib/unirest.php'之前尝试设置代码>-在示例中,出现了“对不起,仍然不工作”和相同的错误。SendGrid::register_autoloader()代码>你把这个放在哪里?