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();
}
}
答案 0 :(得分: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'));
答案 1 :(得分: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');
}
}
答案 2 :(得分: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;
}