Migrating old script to new sendgrid php library errors
<p>I recently installed the new version of sendgrid for my website. I'm getting this errors when running the script:</p>
<blockquote>
<p>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</p>
<p>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</p>
<p>Notice: Undefined variable: name in /var/www/prodweb/web/sendgrid-php/lib/helpers/mail/Mail.php on line 853</p>
<p>Notice: Undefined variable: email in /var/www/prodweb/web/sendgrid-php/lib/helpers/mail/Mail.php on line 854</p>
<p>Fatal error: Call to undefined method SendGrid\Email::addSmtpapiTos() in /var/www/prodweb/web/sengrid.php on line 50</p>
</blockquote>
<p>This is the script i was using before migrating to the last version:</p>
<pre><code>&lt;?php
ini_set(&quot;display_errors&quot;, &quot;1&quot;);
error_reporting(E_ALL);
require_once ('inc/db.php');
require(&quot;sendgrid-php/sendgrid-php.php&quot;);

$sendgrid = new SendGrid('myapikey');

$email    = new SendGrid\Email();

$resultado = mysqli_query($dbc,&quot;SELECT email, hash FROM newsletter WHERE enviado = '0' AND newsletter = '1'&quot;);
$totalRows = mysqli_num_rows($resultado);
if ($totalRows == 0){ // Si no encuentra registros, muestra la notificacion correspondiente
    echo &quot;&lt;p&gt;No existen resultados que coincidan con tu busqueda&lt;/p&gt;&quot;;
}

$all_users = array(); // intialzie array

while ($usuario = mysqli_fetch_array($resultado, MYSQLI_ASSOC)) {
    $usermail = $usuario['email']; 
    $hash = $usuario['hash'];
    mysqli_query($dbc, &quot;UPDATE newsletter SET enviado = '1' WHERE email='$usermail' &quot;); 

    $all_users[] = $usermail; // push all emails first
}

// then send

try {
    $email-&gt;addSmtpapiTos($all_users)
    -&gt;setFrom(&quot;no_responder@test.com.ar&quot;)
    -&gt;setFromName(&quot;test&quot;)
    -&gt;setReplyTo(&quot;no_responder@test.com.ar&quot;)
    -&gt;setSubject(&quot;Convocatorias Semanales&quot;)
    -&gt;setHtml('test');

    $result = $sendgrid-&gt;send($email);
    echo &quot;enviado&quot;;
} catch(\SendGrid\Exception $e) {
    echo $e-&gt;getCode() . &quot;\n&quot;;
    foreach($e-&gt;getErrors() as $er) {
        echo $er;
    }
}
</code></pre>
<p>How can i solve this?</p>