3

swiftmailerとsendgridsmtpを使用して電子メールを送信しようとすると、このエラーが発生します

致命的なエラー: *キャッチされなかった例外'Swift_TransportException'とメッセージ'応答コード250が必要ですが、コード ""が表示され、メッセージ""'が表示されます*

これが私のコードです:

$hdr = new SmtpApiHeader();


// Set all of the above variables
$hdr->addTo($toList);
$hdr->addSubVal('-name-', $nameList);
$hdr->addSubVal('-time-', $timeList);

// Specify that this is an initial contact message
$hdr->setCategory("initial");

// The subject of your email
$subject = 'Example SendGrid Email';

// Where is this message coming from. For example, this message can be from 
// support@yourcompany.com, info@yourcompany.com
$from = array('no-reply@mupiz.com' => 'Mupiz');
$to = array('antonin@noos.fr'=>'AN',"antonin@mupiz.com"=>"AN2s");

$text="Hello -name-
       Thank you for your interest in our products. We have set up an appointment
             to call you at -time- EST to discuss your needs in more detail.

                Regards,

                Fred, How are you?
      ";
$html = "
<html>
  <head></head>
  <body>
    <p>Hello -name-,<br>
       Thank you for your interest in our products. We have set up an appointment
             to call you at -time- EST to discuss your needs in more detail.

                Regards,

                Fred, How are you?<br>
    </p>
  </body>
</html>
";

// Your SendGrid account credentials
$username = 'XXXX';
$password = 'XXXX';

// Create new swift connection and authenticate
$transport = Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 25);
$transport ->setUsername($username);
$transport ->setPassword($password);
$swift = Swift_Mailer::newInstance($transport);

// Create a message (subject)
$message = new Swift_Message($subject);

// add SMTPAPI header to the message
// *****IMPORTANT NOTE*****
// SendGrid's asJSON function escapes characters. If you are using Swift Mailer's
// PHP Mailer functions, the getTextHeader function will also escape characters.
// This can cause the filter to be dropped.
$headers = $message->getHeaders();
$headers->addTextHeader('X-SMTPAPI', $hdr->asJSON());

// attach the body of the email
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');

// send message
if ($recipients = $swift->send($message, $failures))
{
// This will let us know how many users received this message
// If we specify the names in the X-SMTPAPI header, then this will always be 1.
echo 'Message sent out to '.$recipients.' users';
}
// something went wrong =(
else
{
echo "Something went wrong - ";
print_r($failures);
}

アイデア ?

ありがとう

4

3 に答える 3

3

sendgrid の場合、次の 2 つの理由が考えられます。

  1. 認証データが間違っている可能性があります

  2. アカウントはまだプロビジョニングされている可能性があるため、完全にアクティブ化されるまで少し待つ必要があります

それで

  • app/config/mail.php のすべての認証データをチェックして、https://sendgrid.com/docs/Integrate/index.html のデータと一致するようにします

  • sendgrid アカウントに次のようなトップメッセージ/通知がないことも確認してください。

アカウントはまだ準備中です。メールを送信できない可能性があります。

于 2014-11-28T10:20:45.143 に答える
3

これにはいくつかの原因が考えられます。最も可能性が高いのは、サーバーの外部ホストへの接続がオフになっていることです。その他の可能性としては、openSSL エラーのある古いバージョンの PHP を使用しているか、何かによって速度が制限されている可能性があります。

外部ホストの問題の詳細については、この質問をご覧ください: sendgrid 経由でメールを送信する


別途、SendGrid を使用してメールを送信する場合は、SendGrid PHP ライブラリを使用する必要があります。これは、Swift と一般的な送信に関する一連の微妙なニュアンスに対処します。また、何らかの理由で SMTP を使用できない場合に備えて、HTTP API にアクセスできます。

https://github.com/sendgrid/sendgrid-php

完全開示: 私は SendGrid の開発者エバンジェリストとして働いており、時々 PHP ライブラリに取り組んでいます。

于 2012-06-22T18:20:11.023 に答える
0

請求上の理由 (クレジット カードの有効期限切れなど) でアカウントが凍結されている場合にも、このエラーが表示されます。

注: SendGrid はメッセージをドロップしません。課金の問題が解決されるまでメッセージを保持し、このエラーが返された場合でもメッセージを処理します。

于 2016-09-08T15:45:32.863 に答える