【问题标题】:Migrating old script to new sendgrid php library errors将旧脚本迁移到新的 sendgrid php 库错误
【发布时间】:2016-08-29 19:17:49
【问题描述】:

我最近为我的网站安装了新版本的 sendgrid。运行脚本时出现此错误:

警告:SendGrid\Email::__construct() 缺少参数 1,在第 9 行的 /var/www/prodweb/web/sengrid.php 中调用并在 /var/www/prodweb/web/sendgrid-php 中定义/lib/helpers/mail/Mail.php 在第 851 行

警告:SendGrid\Email::__construct() 缺少参数 2,在第 9 行的 /var/www/prodweb/web/sengrid.php 中调用并在 /var/www/prodweb/web/sendgrid-php 中定义/lib/helpers/mail/Mail.php 在第 851 行

注意:未定义变量:第 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;
    }
}

我该如何解决这个问题?

【问题讨论】:

    标签: php sendgrid


    【解决方案1】:

    修改:

    $email    = new SendGrid\Email();
    

    成为:

    $email    = new SendGrid\Mail();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多