Sending email using function drupal_mail(). All you need to do is install and configure SMTP module and then add the given code in your custom module.
function sendemail(){
$to = ' xyz@gmail.com ';
$from = ' abc@gmail.com ';
$subject = ' Subject of your mail ';
$msg = " Hello dear,how are you ? ";
mymodule_mail($from,$to, $subject, $message);
}
/**
* * Implementation of hook_mail().
*/
function mymodule_mail($from, $to, $subject, $message) {
$my_module = ' mymodule ';
$my_mail_token = microtime();
$message = array(
'id' => $my_module . '_' . $my_mail_token,
'to' => $to,
'subject' => $subject,
'body' => array($message),
'headers' => array(
'From' => $from,
'Sender' => $from,
'Return-Path' => $from,
'MIME-Version' => '1.0',
'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
'Content-Transfer-Encoding' => '8Bit',
'X-Mailer' => 'Drupal'
),
);
$system = drupal_mail_system($my_module, $my_mail_token);
$message = $system->format($message);
$system->mail($message);
}
0 Comment(s)