1

first time questioning so go easy on me and if you need anything else, just ask

For a job interview i need to create a small mailing app using PHP and Postmark. The ui is ugly, but its not supposed to be pretty, my HTML layout skills have already been proven. So it's just the PHP functionality i need.

So, to my actual question: I'm populating an array using the following code

$message = array(
    //'To' => filter_input(INPUT_POST, 'To'),
    //'From' => filter_input(INPUT_POST, 'From'),
    //'Cc' => filter_input(INPUT_POST, 'Cc'),
    //'Bcc' => filter_input(INPUT_POST, 'Bcc'),
    //'Subject' => filter_input(INPUT_POST, 'Subject'),
    //'TextBody' => filter_input(INPUT_POST, 'TextBody')
    'To' => "roderikmasure@gmail.com",
    'From' => "roderik@masure.org",
    'Cc' => "mistermorgoth666@gmail.com",
    'Subject' => "Test",
    'TextBody' => "Dit is een testmail, ik hoop dat het nu eindelijk werkt."
);

$client = new PostmarkClient("<API TOKEN>");

$sendResult = $client->sendEmailBatch($message);

pretty straightforward, should be no problem, i think. nevertheless i keep getting the same error:

Warning: Invalid argument supplied for foreach() in /srv/www/sites/roderik/vendor/wildbit/postmark-php/src/Postmark/PostmarkClient.php on line 136 Warning: Invalid argument supplied for foreach() in /srv/www/sites/roderik/vendor/wildbit/postmark-php/src/Postmark/PostmarkClient.php on line 136 Warning: Invalid argument supplied for foreach() in /srv/www/sites/roderik/vendor/wildbit/postmark-php/src/Postmark/PostmarkClient.php on line 136 Warning: Invalid argument supplied for foreach() in /srv/www/sites/roderik/vendor/wildbit/postmark-php/src/Postmark/PostmarkClient.php on line 136 Warning: Invalid argument supplied for foreach() in /srv/www/sites/roderik/vendor/wildbit/postmark-php/src/Postmark/PostmarkClient.php on line 136 Parse error: syntax error, unexpected T_USE, expecting T_FUNCTION in /srv/www/sites/roderik/vendor/guzzlehttp/guzzle/src/Client.php on line 20

I've checked the code at line 136 multiple times and i have no idea what gives the error.

here's the code from line 136 (second line is 136):

foreach ($emailBatch as $key => $email) {
        foreach ($email as $emailIdx => $emailValue) {
            if (strtolower($emailIdx) == 'headers') {
                $email[$emailIdx] = $this->fixHeaders($emailValue);
            }
        }
        array_push($final, $email);
    }

therefore it seems that the error is in the auto generated files from Postmark but i have no idea how to fix it.

Has any of you had this problem and found a solution? if you do it would be great if you could help me

Git Repository

Actual app (ftp server)

Thank you very much

Edit - Just noticed the ftp server runs PHP 5.3.3, I'll try to update it to 5.4. It seems most problems were related to that.

Community
  • 1
  • 1

1 Answers1

2
$message = array(
    array(
        //'To' => filter_input(INPUT_POST, 'To'),
        //'From' => filter_input(INPUT_POST, 'From'),
        //'Cc' => filter_input(INPUT_POST, 'Cc'),
        //'Bcc' => filter_input(INPUT_POST, 'Bcc'),
        //'Subject' => filter_input(INPUT_POST, 'Subject'),
        //'TextBody' => filter_input(INPUT_POST, 'TextBody')
        'To' => "roderikmasure@gmail.com",
        'From' => "roderik@masure.org",
        'Cc' => "mistermorgoth666@gmail.com",
        'Subject' => "Test",
        'TextBody' => "Dit is een testmail, ik hoop dat het nu eindelijk werkt."
    )
);

$client = new PostmarkClient("f92ee11a-3de9-48ff-801e-1b6efc9afcdf");

$sendResult = $client->sendEmailBatch($message);

It expects it to be multi-dimensional. It is a batch after all.

Flosculus
  • 6,880
  • 3
  • 18
  • 42