Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 发送电子邮件drupal 7,附件文件类型为pdf文档和docx_Php_Drupal_Drupal 7 - Fatal编程技术网

Php 发送电子邮件drupal 7,附件文件类型为pdf文档和docx

Php 发送电子邮件drupal 7,附件文件类型为pdf文档和docx,php,drupal,drupal-7,Php,Drupal,Drupal 7,你能帮我吗 保存节点后,我编写此代码发送节点 此节点有一个附加文件,可以是pdf文档和docx 我用过这个钩子 这可能会发送一封带有html附件的空邮件,其中包含邮件正文而不是文件内容 function footer_node_insert($node){ if($node->type=="application_form"){ $file_data=file_load($node->field_cv['und'][0]['fid']); $filemime=

你能帮我吗 保存节点后,我编写此代码发送节点 此节点有一个附加文件,可以是pdf文档和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();

}
函数页脚\节点\插入($node){
如果($node->type==“应用程序表单”){
$file_data=file_load($node->field_cv['und'][0]['fid']);
$filemime=$file\u data->filemime;
$filename=$file\u data->filename;
$file\u uri=file\u create\u url($file\u data->uri);
$job=node_load($node->field_apply['und'][0]['nid']);
$to$mail@mail.com';
$key=“通知”;
$module='footer';
$message=drupal\u mail($module,$key,$to,language\u default(),array(),”from@froom.com“,对);
//构建默认的头文件
$headers=数组(
“MIME版本”=>“1.0”,
'内容类型'=>'文本/html;字符集=UTF-8;格式=流动;delsp=是',
'内容传输编码'=>'8位',
“X-Mailer”=>“Drupal”,
); 
$attachment=array(
“filecontent”=>文件获取内容($file\u uri),
'filename'=>$filename,
“filemime”=>$filemime
);
$message['headers']['Content-Type']=$headers;
$message['subject']='Apply for'.$job->title.'Page';
$body=array();
$body[]='.t('Name:')。$node->title;
$body[]='.t('Email:')。$node->field_application_Email['und']['0']['Email'];
$body[]='.t('Current Job:')。$node->field_Current_Job['und']['0']['value'];
$body[]='.t('当前公司:')。$node->field_Current_Company['und']['0']['value'];
$body[]='.t('Home Phone:')。$node->field_Home_Phone['und']['0']['value'];
$body[]='.t('Mobile Phone:')。$node->field_Mobile_Phone['und']['0']['value'];
$message['body']=内爆(“
”,$body); $message['params']['attachments'][]=$attachment; //检索此消息的负责实现。 $system=drupal\u mail\u系统($module,$key); //格式化消息正文。 //$message=$system->format($message); //发送电子邮件。 $message['result']=$system->mail($message); 如果($message['result'])){ 回声“真”; }否则{ 回声“假”; } 退出(); }

}

我已经做了类似的事情来发送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;
    }
}

像这样升级函数并添加附加文件

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');
        }

    }

我的Drupal 7解决方案使用模块MimeMail,无需调用hook_mail():


您可以使用hook\u mail()尝试drupal\u mail方式
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');
        }

    }
// 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;
}