0

I have a simple copy-paste code from AWS SES PHP SDK v3 to send bulk emails using sendTemplatedEmail function.

but it's throwing this error:

 Type: ParseError

    Message: syntax error, unexpected ',', expecting ';'
    
    Filename: /home/sites/10a/9/9bdb792fe4/public_html/application/third_party/amazon_ses/vendor/aws/aws-sdk-php/src/data/email/2010-12-01/api-2.json.php
    
    Line Number: 3
File: /home/sites/10a/9/9bdb792fe4/public_html/application/helpers/amazonses_helper.php
Line: 24
Function: __construct

This is the code and the error is at line number 24 which is the line where I am providing the credentials i.e., 'credentials' => [ 'key' => AMAZON_SES_KEY_ID, 'secret' => AMAZON_SES_SECRET_KEY ]

public static function send_bulk_mail($data)
{   
    
    $SesClient = new Aws\Ses\SesClient([
        'profile' => 'default',
        'version' => '2010-12-01',
        'region' => 'eu-west-1',
        'credentials' => [ 'key' => AMAZON_SES_KEY_ID, 'secret' => AMAZON_SES_SECRET_KEY ]
    ]);
    
    $template_name = 'default';
    $sender_email = 'support@example.com';
    $recipient_emails = array();
    
    foreach($data['recipients'] as $index => $person){
        $recipient_emails[$index] =  $person['email'];
    }
    
    
    
    
    try {
        $result = $SesClient->sendTemplatedEmail([
            'Destination' => [
                'ToAddresses' => $recipient_emails,
            ],
            'ReplyToAddresses' => [$sender_email],
            'Source' => $sender_email,
    
            'Template' => $template_name,
            'TemplateData' => '{ }'
        ]);
        var_dump($result);
    } catch (AwsException $e) {
        // output error message if fails
        echo $e->getMessage();
        echo "\n";
    }
     
}
Lonare
  • 3,581
  • 1
  • 41
  • 45
  • The error mentions `api-2.json.php` on line 3, and `amazonses_helper.php` on line 24. Check those files and locations for parse errors. – aynber Jun 24 '20 at 13:23
  • @aynber sorry i didn't mentioned before but amazonses_helper.php is the file which has this code. and api-2.json.php is AWS code I dont want to change there anything.... – Lonare Jun 24 '20 at 13:33
  • It could be something as simple as a bad file encoding messing things up. You can check which file it is with `php -r /home/sites/10a/9/9bdb792fe4/public_html/application/third_party/amazon_ses/vendor/aws/aws-sdk-php/src/data/email/2010-12-01/api-2.json.php` and `php -r /home/sites/10a/9/9bdb792fe4/public_html/application/helpers/amazonses_helper.php` from the command line. Parse errors are thrown immediately. – aynber Jun 24 '20 at 13:55

0 Answers0