我最近为我的网站安装了新版本的sendgrid。我在运行脚本时遇到了这个错误:
警告:缺少SendGrid \ Email :: __ construct()的参数1,在第9行的/var/www/prodweb/web/sengrid.php中调用,并在/ var / www / prodweb / web / sendgrid-php中定义第851行的/lib/helpers/mail/Mail.php
警告:缺少SendGrid \ Email :: __ construct()的参数2,在第9行的/var/www/prodweb/web/sengrid.php中调用,并在/ var / www / prodweb / web / sendgrid-php中定义第851行的/lib/helpers/mail/Mail.php
注意:未定义的变量:第853行的/var/www/prodweb/web/sendgrid-php/lib/helpers/mail/Mail.php中的名称
注意:未定义的变量:第854行的/var/www/prodweb/web/sendgrid-php/lib/helpers/mail/Mail.php中的电子邮件
致命错误:在第50行的/var/www/prodweb/web/sengrid.php中调用未定义的方法SendGrid \ Email :: addSmtpapiTos()
这是我在迁移到上一个版本之前使用的脚本:
<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
require_once ('inc/db.php');
require("sendgrid-php/sendgrid-php.php");
$sendgrid = new SendGrid('myapikey');
$email = new SendGrid\Email();
$resultado = mysqli_query($dbc,"SELECT email, hash FROM newsletter WHERE enviado = '0' AND newsletter = '1'");
$totalRows = mysqli_num_rows($resultado);
if ($totalRows == 0){ // Si no encuentra registros, muestra la notificacion correspondiente
echo "<p>No existen resultados que coincidan con tu busqueda</p>";
}
$all_users = array(); // intialzie array
while ($usuario = mysqli_fetch_array($resultado, MYSQLI_ASSOC)) {
$usermail = $usuario['email'];
$hash = $usuario['hash'];
mysqli_query($dbc, "UPDATE newsletter SET enviado = '1' WHERE email='$usermail' ");
$all_users[] = $usermail; // push all emails first
}
// then send
try {
$email->addSmtpapiTos($all_users)
->setFrom("no_responder@test.com.ar")
->setFromName("test")
->setReplyTo("no_responder@test.com.ar")
->setSubject("Convocatorias Semanales")
->setHtml('test');
$result = $sendgrid->send($email);
echo "enviado";
} catch(\SendGrid\Exception $e) {
echo $e->getCode() . "\n";
foreach($e->getErrors() as $er) {
echo $er;
}
}
我该如何解决这个问题?
答案 0 :(得分:0)
修改:
$email = new SendGrid\Email();
是:
$email = new SendGrid\Mail();