0

Hiawatha サーバーで実行されている AWS SES アカウント (本番モード) を介して CakePHP 3 を使用してメールを送信しようとすると、3 回目または場合によっては最初の試みの後に、「Internal Server Error 500」が表示されます。

これが私のphpコードです:

  public function sendmail()
{
    $email = new Email();
    $email->transport('SES');
    try {
        $res = $email->from(['account@example.com' => 'Name'])
              ->to(['receiver@hotmail.com' => 'Receiver'])
              ->subject('Test mail')
              ->send('some text');
    } catch (Exception $e) {
        $this->Flash->error('Error. Please, try again.');
        echo 'Exception : ',  $e->getMessage(), "\n";
        return $this->redirect('/');
    }
    $this->Flash->success('Ok. You will receive a confirmation mail');
    return $this->redirect('/');} 

これがトランスポート構成です

     'EmailTransport' => [
     'SES' => [
         'host' => 'email-smtp.eu-west-1.amazonaws.com',
         'port' => 25,
         'timeout' => 60,
         'username' => 'ASDFASADQWE',
         'password' => 'FSDFDSFDSFSEREWRWERWER',
         'tls' => true,
         'className' => 'Smtp'
     ],

ポート 465 と 587 が最初の試行で機能しない

したがって、基本的に、問題が CakePHP、AWS SES、またはサーバー上の何らかの構成に起因するものかどうかを特定できません。

お勧めいただきありがとうございます。

4

1 に答える 1

0

最後に、cakePHP メールの使用を停止し、PHPMailer をセットアップします。構成を使用して実行するにはいくつかの問題がありますが、最後に、これは多くのメールを連続して送信できる作業コードです。

   public function sendMailPHPMailer()
    {
      $mail = new \PHPMailer();
      $mail->isSMTP();                                      
      $mail->Host = 'email-smtp.eu-west-1.amazonaws.com';  
      $mail->SMTPAuth = true;                              
      $mail->Username = 'username'; 
      $mail->Password = 'password';
      $mail->SMTPSecure = 'tls';    
      $mail->Port = 587;                               
      $mail->From = 'mail@mail.com';
      $mail->FromName = 'cakePHP PHPMailer';
      $mail->addAddress('tomail@mail.com', 'receiver');
      $mail->isHTML(true);                               
      $mail->Subject = 'Test using PHPMailer & SES';
      $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
      $mail->AltBody = 'This is the body in plain text';

      if(!$mail->send()) {
          $this->Flash->error('error');
          echo 'Exception : ',  $mail->ErrorInfo, "\n";
          return $this->redirect('/');
        }else{
          $this->Flash->success('ok');
          return $this->redirect('/');
        }
    }

このコードでは、1 秒間隔で 3 つのメールしか送信できず、エラー 500 が返されます。

    public function sendmail()
    {
        $email = new Email();
        $email->transport('SES');
        try {
            $res = $email->from(['mail@mail.com' => 'cakePHP mail'])
                  ->to(['tomail@mail.com' => 'receiver'])
                  ->subject('cakePHP & SES')
                  ->send('message via cakePHP and SES');
        } catch (Exception $e) {
            $this->Flash->error('error');
            echo 'Exception : ',  $e->getMessage(), "\n";
            return $this->redirect('/');
        }
        $this->Flash->success('ok');
        return $this->redirect('/');
}
于 2015-04-15T19:47:51.243 に答える