cluesshop.com

Sunday, 4 May 2014

drupl send email by uisng custome block


//.info

name = Common Services Module
description = A Common Service Module for all Common Services Usage
core = 7.x
package =Claim Jockey



/////.moule

<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Implements hook_block_info().
 *
 * This function tells drupal about our block.
 *
 * For more information on this function, see:
 * http://api.drupal.org/api/drupal/modules block block.api.php/function/hook_block_info/7
 */
function contactblock_us_block_info() {
        // Create an array that will hold our blocks
        $blocks = array();
        $blocks['contactblock_us_form'] = array(
                'info' => t('contactblock_us'),
                // 'cache' how this block will be cached
                'cache' => DRUPAL_CACHE_GLOBAL,
        );
        return $blocks;
}

/**
 * Implements hook_block_view().
 *
 * This function tells drupal how to define our block when viewed.
 *
 * For more information on this function, see:
 * http://api.drupal.org/api/drupal/modules block block.api.php/function/hook_block_view/7
 */
function contactblock_us_block_view($delta = '') {
        // Create an array that will be returned as our block
        $block = array();
        switch($delta) {
                case 'contactblock_us_form':
                        $block['subject'] = t('Contactblock');
                        $block['content'] = drupal_get_form('contactblock_us_form');
                break;
        }

        // Finally, we return the $block array.
        return $block;
}

/**
 * Define the form to be returned.
 *
 * Note that drupal passes in two parameters,
 * $form - which holds all of the elements of the form
 * $form_state - a special array of settings & values needed by Drupal
 */
function contactblock_us_form($form, &$form_state) {
      $form['Subscribe_Email'] = array(
                '#type' => 'textfield',
                '#required' => TRUE,
                '#title' => t("Email"),
                '#description' => t('Must be a valid email address'),
        );
      $form['Describes_boxes'] = array(
                '#type'            => 'checkboxes',
                    '#title' => t('Which Describes You(Check as many as apply):'),
                '#options'         => array(
                     'Family Member / Friend Of Policyholder' => 'Family Member / Friend Of Policyholder',
                     'On Claim' => 'On Claim',
                     'Policyholder' => 'Policyholder',
                     'Soon-to-be-on-Claim' => 'Soon-to-be-on-Claim',
                     'Professional Care Provider' => 'Professional Care Provider',
                     'Attorney' => 'Attorney',
                     'Insurance Agent' => 'Insurance Agent',
                     'Insurance Company' => 'Insurance Company',
                     'Other' => 'Other',
                  ),
        '#default_value'   => variable_get('boxes', 0),
         '#required' => TRUE,
     );
        $form['submit'] = array(
                '#type' => 'submit',
                '#value' => t('Submit'),
        );

        return $form;
}

/*
 * Define a validation function that drupal will
 */
function contactblock_us_form_validate($form, &$form_state) {
        $email = $form_state['values']['Subscribe_Email'];
        if(valid_email_address($email) == 0) {
                form_set_error('Subscribe_Email', t('Not a valid email address'));
        }
}
//
/*
 * Define a submit funciton that drupal will
 * automatically call when submit is pressed (and all validators pass)
 */
function contactblock_us_form_submit($form, &$form_state) {
        $email = $form_state['values']['Subscribe_Email'];
       $selected = array();
     
//       $selected=$form_state['values']['Describes_boxes'];
       foreach($form_state['values']['Describes_boxes'] as $a => $b)
     {
       if((string)$b != "0")
       {
         $selected[] = $b;
      }
     }
   
        $params[] =$selected;
       
             $params = array(
    'Email' => $email,
    'checkedboxes' => $selected,          
    );
        $message = drupal_mail('contactblock_us', 'notify', $email, language_default(),$params, $from);
        if(!empty($message['result'])) {
                drupal_set_message(t('Thank you for subscribing to our newsletter!  The ClaimJockey family.'));
        } else {
                drupal_set_message(t('There was a problem Thank you for subscribing to our newsletter!  The ClaimJockey family.', 'error'));
        }
}

/**
 * Implements hook_mail().
 */
function contactblock_us_mail($key, &$message, $params,$form) {
        global $base_url;
    $output=array();
     $paramser=$params['checkedboxes'];
    foreach($paramser as $paramsvalues){
        $output[]=$paramsvalues;
}

   $str = implode (", ", $output);
        $message['subject'] = t('Thank you for subscribing to our newsletter! The ClaimJockey family.');
//        $message['body'][] = t("Hello,\nYour friend thought you might like this site.  Please click the link below to visit.\n\n!link", array('!link' => $base_url));    
         $body = '';
            $body = $body . '<html>
              <body style="margin=0px; padding:0px;">
         
            <table style="border-collapse: collapse">
            <tbody style="border:1px solid">
            <tr style="border:1px solid">
            <td style="border:1px solid"><label>Email:</label></td>
             <td style="border:1px solid">'.$params['Email'].'</td>
            </tr>
           <tr style="border:1px solid">
           <td style="border:1px solid">
            <label>Which Describe You (Check as many as apply)</label></td><td style="border:1px solid">'.$str.'</td></tr>
            <tr style="border:1px solid">
            <tr style="border:1px solid">
            </tbody>
            </table>
            </html>';
//$params['Family'].$params['On_Claim'].$params['Policyholder'].$params['Soon_to_be_on_Claim'].$params['Professional'];
       
        $message['body'][]= $body;
        $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed';
        }

No comments:

Post a Comment