Como enviar emails en drupal

Para enviar correos en Drupal se debe realizar un procedimiento en 2 etapas.

Primera Etapa - Armar el correo

Aca recolectamos todas la informacion necesaria para enviar el correo y lo enviamos a la cola de correo de Drupal
$to ='youremail@gmail.com;       //gets the current user's mail address
$from = variable_get('site_mail', '');    //admin's mail address
$body = 'Gracias por visitarnos.';
 $attachment = array(
      'filecontent' => file_get_contents('Link to file'),
      'filename' => 'filename.pdf',// You can change the name and extension of the file         you need to send.
      'filemime' => 'text/plain',  
      );
 $params = array(
 'subject' => 'Bienvenido',
 'body' => $body,
 'attachment'=>$attachment,
);
drupal_mail('modulename', 'yourkey', $to, language_default(),$params,$from); 

 

 

Segunda Etapa - Enviar el Correo

En la cola de correos de Drupal, el sistema evalua cada solicitud pendiente de ser enviada y debe llenarse adecuadamente 

function yourmodule_mail($key, &$message, $params){
      switch ($key) {
            case "yourkey":   
                 // Set the mail content type to html to send an html e-mail (optional).
                 $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
                 // Grab the subject and body from params and add it to the message.
                 $message['subject'] = $params['subject'];
                 $message['body'][] = $params['body'];
                 if (isset($params['attachment'])) {
                        $message['params']['attachments'][] = $params['attachment'];
                  }
                  break;
          }
}

 



Contactanos