Example usage of drupal_mail_send()

Just wanted to put this up as a quick example for future usage.

$headers = array(
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal',
);
drupal_mail_send($message = array(
'id' => 'test_test',
'from' => 'test@gmail.com',
'to' => 'test@gmail.com',
'subject' => 'test',
'body' => 'test2',
'headers' => $headers,
));

Comments

The submitted from address () is not valid.

On your implementation of Drupal, you may get this error with the above code: The submitted from address () is not valid.

To fix it, simply add a 'from' variable in the associative array, such as:

drupal_mail_send($message = array(
'id' => 'test_test',
'from' => $FROM_EMAIL,
'to' => $to,
'subject' => $SUBJECT,
'body' => $body,
'headers' => array(
'MIME-Version' => '1.0',
'Content-type' => 'text/html; charset=iso-8859-1',
),
));

Excellent, thanks for this. I

Excellent, thanks for this. I updated the post to reflect your suggestion.

how to send to multiple users...

How can we send emails to multiple users by using this function.. There doesnt seems to be any cc or bcc option available in this function.. Please help..

Good Idea

Excellent, thanks for this. I updated the post to reflect your suggestion.

Add new comment

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Comment using an existing account (Google, Twitter, etc.)