2013-08-19 4 views
2

drupal_mail()에 문제가 있습니다. 이메일을 받았지만 제목과 본문이 비어 있습니다.Drupal_mail() 비어있는 본문 및 제목 없음

$params = array(
    'subject' => t('Client Requests Quote'), 
    'body' => t("Body of the email goes here"), 
); 
drupal_mail("samplemail", "samplemail_html_mail", "[email protected]", language_default(), $params, "[email protected]", TRUE); 

아래

드루팔 버전 7

코드가 난 아래 훅을 시도하고 난 같은 결과를 얻을.

function hook_mail($key, &$message, $params) { 
switch ($key) { 
    case 'samplemail_html_mail': 
     /* 
     * Emails with this key will be HTML emails, 
     * we therefore cannot use drupal default headers, but set our own headers 
     */ 
     /* 
     * $vars required even if not used to get $language in there since t takes in: t($string, $args = array(), $langcode = NULL) */ 
     $message['subject'] = t($params['subject'], $var, $language->language); 
     /* the email body is here, inside the $message array */ 
     $body = "<html><body> 
      <h2>HTML Email Sample with Drupal</h2> 
      <hr /><br /><br /> 
      {$params['body']} 
      </body></html>"; 
     $message['body'][] = $body; 
     $message['headers']['Content-Type'] = 'text/html; charset=UTF-8; format=flowed'; 
     break; 
} 
} 

drupal_mail_system() 작동하지만 일반 텍스트로 제공됩니다.

+0

'hook'을 모듈 이름으로 바꾸어야합니다. 예 : 'function mymodule_mail (' – jantimon

+0

여전히 작동하지 않습니다. 같은 문제입니다. 본문이나 제목이 없습니다. – user742736

답변

3

모듈에서는 hook_mail을 사용하지 말아야합니다. _hook()이어야합니다.

변경 * 기능 hook_mail ($ 키, & $ 메시지, $의 PARAMS) {* 기능 samplemail_mail ($ 키, & $ 메시지, $의 PARAMS) {에

+0

여전히 작동하지 않습니다. 빈 몸체와 제목을 받고 있습니다. hook_function_mail이 이제 registration_form_mail 모듈 이름입니다. – user742736

+0

[해결책] (http://stackoverflow.com/questions/18306832/drupal-mail-empty-body-and-no-subject/18458890#18458890) 이것을 확인하십시오. – shangan

1

다음 코드를 사용해보십시오.

// Use these two lines when you want to send a mail. 
global $user; 
drupal_mail('test', 'test_mail', 'your_mail_id', user_preferred_language($user), $params, $from_mail_id, TRUE); 

/** 
* Implements hook_mail(). 
*/ 
function test_mail($key, &$message, $params) { 
    switch ($key) { 
    case 'test_mail': 
     $params['subject'] = t('Subject is here'); 
     $params['message'] = 'message is here'; 
     $message['subject'] = $params['subject']; 
     $message['body'][] = $params['message']; 
     break; 
    } 
} 

참고 : '테스트'모듈 이름입니다.

0

솔루션!

"registration_form"모듈에서 아래 코드를 사용해보십시오. 이 코드는 메일 트리거가 hook_init에서 수행되므로 페이지를 새로 고침 할 때 자주 메일을 보냅니다. 언제 어디서나 사용하십시오.



    /** 
    * Implements hook_init(); 
    */ 
    function registration_form_init() { 
    $first_name = 'Shankar'; 
    $params = array(
        'subject' => 'Signup Invitation', 
        'body' => '<p>Dear ' . $first_name . ',</p> 
           <p>Congratulations! Your account <b> ' . $first_name . ' </b>has been successfully created with SOME portal.</p> 
               <p>Thanks,SOME portal POSTMASTER</p>', 
        'first_name' => $first_name 
       ); 
       drupal_mail('registration_form', 'invitation', $email, language_default(), $params);  
    } 
    /** 
    * Implements hook_mail(); 
    */ 
    function registration_form_mail($key, &$message, $params) { 
     switch ($key) { 
      case 'invitation':  
       $message['subject'] = $params['subject']; 
       $message['body'][] = $params['body']; 
       break; 
     } 
    } 

관련 문제