簡體   English   中英

使用Hiawatha上運行的cakephp將郵件發送到AWS SES時發生內部服務器錯誤500

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

在第三次或有時是第一次嘗試通過Hiawatha服務器上運行的AWS SES帳戶(處於生產模式)使用CakePHP 3發送郵件時,出現“內部服務器錯誤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或服務器上的某些配置。

感謝您的任何建議。

最后,我停止使用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('/');
        }
    }

使用此代碼,我只能發送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