简体   繁体   English

使用Hiawatha上运行的cakephp将邮件发送到AWS SES时发生内部服务器错误500

[英]Internal Server Error 500 when sending mail to AWS SES with cakephp running on Hiawatha

I'm getting "Internal Server Error 500" after the third or sometimes at the first attempt to send a mail using CakePHP 3 through AWS SES account (in production mode) running on Hiawatha server. 在第三次或有时是第一次尝试通过Hiawatha服务器上运行的AWS SES帐户(处于生产模式)使用CakePHP 3发送邮件时,出现“内部服务器错误500”。

Here is my php code: 这是我的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('/');} 

Here is the transport configuration 这是传输配置

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

port 465 and 587 are not working at the first attemp 端口465和587在第一次尝试时不工作

So, basically I can't identify if the problem came from CakePHP, AWS SES or some configuration on the server. 因此,基本上我无法确定问题是否来自CakePHP,AWS SES或服务器上的某些配置。

Thank you for any recommendation. 感谢您的任何建议。

At the end I stop to use cakePHP mail and setup PHPMailer, some difficulties to use compose and make it run, however at the end this is the working code that I can send many mails in a row. 最后,我停止使用cakePHP邮件并设置PHPMailer,使用compose并使之运行起来有些困难,但是最后,这是可以连续发送许多邮件的工作代码。

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

And with this code I can send only 3 mails with an interval of 1s then I receive an error 500. 使用此代码,我只能发送3封间隔为1s的邮件,然后收到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('/');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM