How to send emails on Drupal in PHP code?

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


 $from_site = variable_get('site_mail', ini_get('sendmail_from')); // fetch site-email address.

  if ($from_site) {
    $headers['Sender'] = $headers['Return-Path'] = $headers['Errors-To'] = $from_site;
  }

 

if (!($success = drupal_mail('invite-mail', $toemail , $subject, wordwrap($body, 72), $from_site, $headers))) {
    static $error_shown = FALSE;
    if (!$error_shown) {
      drupal_set_message(t('Problems occurred while sending the invitation(s). Please contact the site administrator.'), 'error');
      $error_shown = TRUE;
    }

}

                                     

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.