使用php发送多个邮件不起作用

时间:2016-09-22 06:19:05

标签: php email

我正在使用PHP sendgrid库,当我输入多封电子邮件时,我收到了电子邮件,但只收到了我收到的第一封电子邮件,而不是其他电子邮件没有收到任何内容。我做var dump $ mails它有数组。

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();
    }
}

0 个答案:

没有答案