Hi. I noticed when using this module with SMTP and MIMEmail modules that I got errors when it tried to send. On closer inspection it was because the mail body is prepared as a string instead of an array. This was causing a fatal error with the SMTP mailer module.

This is the problem:
$params['body'] = theme('commerce_abandoned_carts_email', array(

This is the fix:
$params['body'][] = theme('commerce_abandoned_carts_email', array(

Comments

very_random_man created an issue. See original summary.

3cwebdev’s picture

Hi. I triggered some test emails with the module as it is now and the messages were received as expected with the body intact. I then changed $params['body'] to add an array key [] as you suggested and my test email body is now empty.

There must be something in your site setup that conflicting in some way and causing the issue.

very_random_man’s picture

Hi. Which mailsystem are you using? We're not doing anything particularly weird although we are using the mimemail and SMTP modules. I think if you test with the SMTP mailsystem you'll see the error.

I think you must agree that $params['body'] is being set to a string value? The docs state that it should be an array.
https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...

This is a snippet from the SMTP module which is where the error occurs if the message body isn't an array:

  public function format(array $message) {
...
    // Join the body array into one string.
    $message['body'] = implode("\n\n", $message['body']);
...

Currently I have fixed this by adding this code to hook_commerce_abandoned_carts_mail_data_alter()

  if (!is_array($params['body'])) {
    $params['body'] = array($params['body']);
  }

  • quantumized committed c8679b2 on 7.x-1.x
    Issue #2960627: Message body string instead of array
    
3cwebdev’s picture

@Comment #3very_random_man, thank you for the information. I finally had some time today to look into this a bit more. I restructured some of the code and was able to get it to work with my mail system (Mandrill) while setting $params['body'] as an array.

Please test the DEV version to confirm it now works as expected for you. If so, I'll commit to a new release.