Where does drupal_mail() get the return-path and sender? I want to send a simple mail using drupal_mail(). I don't understand from where it gets sender and incorrect_mail@gmail.com as return path. From where does it get this email?

function rappel_mail($key, &amp;$message, $params) {
  switch($key) {
    case 'informations':
      $message['subject'] = $params['subject'];
      $message['body']= $params['body'];
      break;       
  }
}

function my_module_passwordOublie_envoie_password ($email) {
  $response = array();
  global $language;
  $mail_user = user_load_by_mail($email);
  if (!$mail_user) {
    return func_succes(950, $response); // just to check if mail exists
  }
  else {
    $to = 'my.real.email@gmail.com'; 
    $from = 'noreplay@noreplay.com';

    $params = array(
      'body' =&gt; t("hi, you've just received a drupal mail"),
      'subject' =&gt; t("test mailing"),
    );
    $message = drupal_mail('rappel', 'informations', $to, $language-&gt;language, $params, $from, TRUE);
   }
 }


This is Postman response (because I'm working with services on a custom resource that send mail using drupal_mail()).

"Return-Path": "????@gmail.com", &lt;=== those emails are valid (mine too but i've delete this email every where it was ! )
"Sender": "????@gmail.com",&lt;=========
"From": "noreplay@noreplay.com" &lt;=== good one
drupal_mail() gets the value for those headers either from the the value of the site_mail persistent variable (set in admin/config/system/site-information), or from the sendmail_from setting found in php.ini.

The first line of drupal_email() show exactly how the default value for the sender is set.

$default_from = variable_get('site_mail', ini_get('sendmail_from'));


This is then the code that sets the email headers.

  if ($default_from) {

    // To prevent e-mail from looking like spam, the addresses in the Sender and
    // Return-Path headers should have a domain authorized to use the originating
    // SMTP server.
    $headers['From'] = $headers['Sender'] = $headers['Return-Path'] = $default_from;
  }
  if ($from) {
    $headers['From'] = $from;
  }
  $message['headers'] = $headers;