Php array error with sendgrid -
this script sending newsletter users. code below has limit 5 testing. i'm having error:
catchable fatal error: argument 1 passed sendgrid\email::settos() must of type array, string given, called in /var/www/web/web/sengrid.php on line 44 , defined in /var/www/web/web/sendgrid-php/lib/sendgrid/email.php on line 90**
<?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 newsletter enviado = '0' , newsletter = '1' limit 5"); $totalrows = mysqli_num_rows($resultado); if ($totalrows == 0){ echo "<p>no results</p>"; } $rss = ""; if(!$xml = simplexml_load_file('http://www.test.com.ar/rss.php') ) { echo 'unable load xml file'; } else { foreach( $xml->channel->aviso $aviso ) { $rss .= "<div class='box-blanco'>"; $rss .= "<a href='$aviso->link' class='link'><p class='titulo'>$aviso->title</p></a>"; $rss .= "<p class='text-muted-2'>$aviso->provincia $aviso->remuneracion</p>"; $rss .= "</div><div class='col-separador-h'></div>"; } }
here loop sending email using settos.
while ($usuario = mysqli_fetch_array($resultado, mysqli_assoc)) { $usermail = $usuario['email']; $hash = $usuario['hash']; $email-> settos($usermail) ->setfrom("no_responder@test.com.ar") ->setfromname("test") ->setreplyto("no_responder@test.com.ar") ->setsubject("convocatorias semanales") ->sethtml('<html><body>test</body></html>'); try { $result = $sendgrid->send($email); mysqli_query($dbc, "update newsletter set enviado = '1' email='$usermail' "); echo "enviado"; } catch(\sendgrid\exception $e) { echo $e->getcode() . "\n"; foreach($e->geterrors() $er) { echo $er; } } } ?>
how can solve this? can't figure out. https://github.com/sendgrid/sendgrid-php/tree/master/lib/helpers/mail
it says expecting array, feed it:
$email-> settos(array($usermail));
this band aid fix though, might want emails first inside container, send it:
$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' email='$usermail' "); $all_users[] = $usermail; // push emails first } // send try { $email->settos($all_users) ->setfrom("no_responder@test.com.ar") ->setfromname("test") ->setreplyto("no_responder@test.com.ar") ->setsubject("convocatorias semanales") ->sethtml('<html><body>test</body></html>'); $result = $sendgrid->send($email); echo "enviado"; } catch(\sendgrid\exception $e) { echo $e->getcode() . "\n"; foreach($e->geterrors() $er) { echo $er; } }
Comments
Post a Comment