0

我在第三次之后或有时在第一次尝试通过在 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 还是服务器上的某些配置。

感谢您的任何建议。

4

1 回答 1

0

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

使用此代码,我只能以 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 回答