We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

amazon SES

[Tue Jun 16 15:42:01.069155 2015] [:error] [pid 4628] [client 192.168.11.10:52122] PHP Catchable fatal error: Argument 1 passed to AmazonSES::__construct() must be of the type array, string given, called in app/library/Mail/Mail.php on line 34 and defined in vendor/amazonwebservices/aws-sdk-for-php/services/ses.class.php on line 71, my function is given below

public function amazonSESSend($to, $subject, $name, $params)
    {

            $this->amazonSes = new \AmazonSES(
                $this->config->amazon->AWSAccessKeyId,
                $this->config->amazon->AWSSecretKey
            );

        $response =$this->amazonSes ->send_raw_email(array(
            'Data' => base64_encode($params),
        ), array(
            'Source' => $to,
            'Destinations' => array(
                $to,
            ),
        ));

        // Success?
        var_dump($response->isOK());
}

According to the documentation, the AmazonSES object must be built using a factory: https://docs.aws.amazon.com/aws-sdk-php/guide/latest/service-ses.html



3.9k

Amazon has updated its API , set composer require "aws/aws-sdk-php": "2.8.8" then code like this:

private function amazonSESSend($raw) {
    if ($this->amazonSes == null) {
        $key = trim($this->config->mail->amazonSES->AWSAccessKeyId);
        $secret = trim($this->config->mail->amazonSES->AWSSecretKey);
        $this->amazonSes = SesClient::factory(array(
            'key' => $key,
            'secret' => $secret,
            // 'ssl.certificate_authority' => BASE_DIR . '/cacert.pem',
            'region' => $this->config->mail->amazonSES->region,
            // 'version' => $this->config->mail->amazonSES->version
        ));
    }

    $response = $this->amazonSes->sendRawEmail(array(
        'RawMessage' => array(
            'Data' => base64_encode($raw)
        )
    ));

    if (!$response) {
        throw new \Exception('Error sending email from AWS SES:' . $response);
    }

    return true;
}