-1

你能帮我写这个代码保存它后发送节点这个节点有一个附件可能是pdf doc和docx我用过这个钩子这可以发送一个带有html附件的空邮件包含邮件正文而不是文件内容

function footer_node_insert($node){


if($node->type=="application_form"){


    $file_data=file_load($node->field_cv['und'][0]['fid']);
    $filemime=$file_data->filemime;
    $filename=$file_data->filename;
    $file_uri=file_create_url($file_data->uri);


    $job=node_load($node->field_apply['und'][0]['nid']);


    $to='mail@mail.com';

    $key = "notice";

    $module = 'footer';

    $message = drupal_mail($module, $key, $to, language_default(), array(), "from@froom.com", True);
    // Build the default headers
    $headers = array(
        'MIME-Version' => '1.0',
        'Content-Type' => 'text/html; charset=UTF-8; format=flowed; delsp=yes',
        'Content-Transfer-Encoding' => '8Bit',
        'X-Mailer' => 'Drupal',
    ); 

    $attachment = array(
    'filecontent' => file_get_contents($file_uri),
    'filename' =>$filename,
    'filemime' =>$filemime
    );


    $message['headers']['Content-Type'] = $headers ;

    $message['subject'] = 'Apply for ' .$job->title  . ' Page';

    $body = array();
    $body[] =   '<b>'. t('Name:').'</b>'.$node->title;
    $body[] =   '<b>'. t('Email:').'</b>'.$node->field_application_email['und']['0']['email'] ; 
    $body[] =   '<b>'. t('Current Job:').'</b>'.$node->field_current_job['und']['0']['value'];
    $body[] =   '<b>'. t('Current Company:').'</b>'.$node->field_current_company['und']['0']['value'];
    $body[] =   '<b>'. t('Home Phone:').'</b>'.$node->field_home_phone['und']['0']['value'];
    $body[] =   '<b>'. t('Mobile Phone:').'</b>'.$node->field_mobile_phone['und']['0']['value'];        

    $message['body'] = implode('<br>', $body);


    $message['params']['attachments'][] = $attachment;
    // Retrieve the responsible implementation for this message.
    $system = drupal_mail_system($module, $key);

    // Format the message body.
    // $message = $system->format($message);

    // Send e-mail.
    $message['result'] = $system->mail($message);

    if ($message['result']) {
    echo 'true';

    } else {
    echo 'false';
    }

exit();

}

}

4

3 回答 3

1

像这样更新您的功能并添加您的附件

function reservation_invitation_mail_send($form_values, $node) {
        $module = 'reservation_invitation';
        $key = 'reservation_invitation_key';
        //$to = $form_values['email'];
        $to= "Yourmail@icilalune.com";
        $cc= $node->content['field_invited_by_ref']['#object']->field_invited_by_ref['und']['0']['entity']->field_email_address['und']['0']['value'];
        $bbc= $node->content['field_invited_by_ref']['#object']->field_main_guest['und']['0']['entity']->field_email_address['und']['0']['value'];
        $from = variable_get('site_mail', 'bacar@icilalune.com');
        $params = $form_values;
        $params['headers'] = array(
            'Bcc' => $bbc,
            'Cc' => $cc);

        $params['subject']= t('Your invitation!');
        $params['body']= theme('reservation_invitation_moet_template',array('var_name'=>$params));
        $language = language_default();
        $send = TRUE;
        variable_set('mail_system', array('reservation_invitation_reservation_invitation_key' => 'ReservationInvitationMailSystem'));
        $message = drupal_mail($module, $key, $to, $language, $params, $from, $send);
      /*  $system = drupal_mail_system($module, $key);
        // Format the message body.
        $message = $system->format($message);
        // Send e-mail.
        $message['result'] = $system->mail($message);*/
        if($message['result'] == TRUE) {
            drupal_set_message(t('Your message has been sent.'));
        }
        else{
            drupal_set_message(t('There was a problem sending your message and it was not sent.'), 'error');
        }

    }
于 2013-04-30T15:36:01.580 回答
1

我已经做了这样的事情来发送 html 邮件。首先,您需要覆盖发送消息的格式。在你的文件 module.inc 中写下这段代码。

     <?php
 change this template use File | Settings | File Templates.
 */

/**
 * Modify the drupal mail system to send HTML emails.
 */
class ReservationInvitationMailSystem extends DefaultMailSystem {
    /**
     * Concatenate and wrap the e-mail body for plain-text mails.
     *
     * @param $message
     *   A message array, as described in hook_mail_alter().
     *
     * @return
     *   The formatted $message.
     */
    public function format(array $message) {
        $message['headers']['Content-Type'] = 'text/html; charset=UTF-8;';
/*        $message['body'] = implode("\n\n", $message['params']['body']);*/
        $message['body'] = drupal_wrap_mail($message['params']['body']);
        return $message;
    }
}

在你的 module.module 之前调用 drupal_mail 设置你的格式邮件

variable_set('mail_system', array('reservation_invitation_reservation_invitation_key' => 'ReservationInvitationMailSystem'));
于 2013-04-30T15:30:58.150 回答
0

我使用模块 MimeMail 的 Drupal 7 解决方案没有调用 hook_mail():

// Load attachment.
$file = file_load($fid);

$to = 'something@email.com';
$from = 'something@email.com';
$subject = 'Invoice ' . $file->filename;

$module = 'mimemail';
$token = time();

$message = array(
  'id' => $module . '_' . $token,
  'to' => $to,
  'subject' => $subject,
  'body' => array('something text...'),
  'headers' => array(
    'From' => $from,
    'Sender' => $from,
    'Return-Path' => $from,
    'MIME-Version' => '1.0',
    'Content-Type' => 'text/html; charset=UTF-8',
  ),
  'params' => array(
    'attachments' => array(
      0 => array(
        'path' => file_stream_wrapper_get_instance_by_uri($file->uri)->realpath(),
        'filecontent' => file_get_contents($file->uri),
        'filename' => $file->filename,
        'mime' => $file->filemime,
        'encoding' => 'base64',
        'disposition' => 'attachment',
        'list' => TRUE,
      ),
    ),
  ),
);

$system = drupal_mail_system($module, $token);
$message = $system->format($message);

if ($system->mail($message)) {
  return TRUE;
}
else {
  return FALSE;
}
于 2014-09-19T09:51:52.420 回答