Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Sending email using drupal_mail()

    • 0
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 337
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: