How to send emails on Drupal in PHP code?



 $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;
    }

}