0

I'm using PHP sendgrid library, I got the email when I entered multiple emails, but only the first email I received something, other than that other emails did not receive anything. I do var dump $mails it has array.

if (isset($_POST['dsubmit'])) {
    $senderid = "no-reply@example.com";
    $receiverid = $_POST["dreceiver"];
    $subject = "Happy Diwali";
    $message = $_POST["dmessage"];

    $sg_username = "abc";
    $sg_password = "abc";

    $sendgrid = new SendGrid($sg_username, $sg_password);

    $mail = new SendGrid\Email();

    $emails = array(
        $receiverid
    );
    foreach ($emails as $recipient) {
        $mail->addTo($recipient);
    }


    try {
        $mail->
                setFrom($senderid)->
                setSubject($subject)->
                setText($message);
        if ($sendgrid->send($mail)) {
            echo "<script type='text/javascript'>console.log('"+var_dump($mail)+"')</script>";
        }
    } catch (Exception $e) {
        echo "Unable to send mail: ", $e->getMessage();
    }
}
dfox
  • 79
  • 3

0 Answers0