2016-08-29 4 views
0

私は最近自分のウェブサイト用の新しいsendgridをインストールしました。古いスクリプトを新しいsendgrid PHPライブラリエラーに移行する

Warning: Missing argument 1 for SendGrid\Email::__construct(), called in /var/www/prodweb/web/sengrid.php on line 9 and defined in /var/www/prodweb/web/sendgrid-php/lib/helpers/mail/Mail.php on line 851

Warning: Missing argument 2 for SendGrid\Email::__construct(), called in /var/www/prodweb/web/sengrid.php on line 9 and defined in /var/www/prodweb/web/sendgrid-php/lib/helpers/mail/Mail.php on line 851

Notice: Undefined variable: name in /var/www/prodweb/web/sendgrid-php/lib/helpers/mail/Mail.php on line 853

Notice: Undefined variable: email in /var/www/prodweb/web/sendgrid-php/lib/helpers/mail/Mail.php on line 854

Fatal error: Call to undefined method SendGrid\Email::addSmtpapiTos() in /var/www/prodweb/web/sengrid.php on line 50

これは私が最後のバージョンに移行する前に使用したスクリプトは次のとおりです:スクリプトを実行しているとき、私はこのエラーを取得してい

<?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("[email protected]") 
    ->setFromName("test") 
    ->setReplyTo("[email protected]") 
    ->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

修正:

$email = new SendGrid\Email(); 

すべき:

$email = new SendGrid\Mail(); 
関連する問題