これは私のすべてのユーザにニュースレターを送るためのスクリプトです。以下のコードにはテストのための制限があります。私は現在、このエラーを抱えている :sendgridでphp配列エラー
Catchable fatal error: Argument 1 passed to SendGrid\Email::setTos() must be of the type array, string given, called in /var/www/web/web/sengrid.php on line 44 and 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 FROM newsletter WHERE enviado = '0' AND 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 to load XML file';
} else {
foreach($xml->channel->aviso as $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>";
}
}
ここsetTosを使用して、すべての電子メールを送信するためのループがあります。
while ($usuario = mysqli_fetch_array($resultado, MYSQLI_ASSOC)) {
$usermail = $usuario['email'];
$hash = $usuario['hash'];
$email-> setTos($usermail)
->setFrom("[email protected]")
->setFromName("test")
->setReplyTo("[email protected]")
->setSubject("Convocatorias Semanales")
->setHtml('<html><body>TEST</body></html>');
try {
$result = $sendgrid->send($email);
mysqli_query($dbc, "UPDATE newsletter SET enviado = '1' WHERE email='$usermail' ");
echo "enviado";
} catch(\SendGrid\Exception $e) {
echo $e->getCode() . "\n";
foreach($e->getErrors() as $er) {
echo $er;
}
}
}
?>
どうすれば解決できますか?私はそれを把握することはできません。 https://github.com/sendgrid/sendgrid-php/tree/master/lib/helpers/mail
私はまだ私はすでに、 '' $編集メール:> setTos($ ALL_USERS)を作っ配列 – Santiago
@Santiagoと同じエラーを持っています – Ghost