Pdf没有附加到我的电子邮件中

时间:2016-06-02 08:40:32

标签: codeigniter codeigniter-2 phpmailer codeigniter-3

我编写了一个函数,用attachment.i发送电子邮件,使用PHPMailer类。 电子邮件已发送,但附件未送达。

我的控制器代码

public function send_mail() 
      {
        $this->load->library('email');

            $subject = 'Request For Quotation';
            $message = '<p>This message has been sent for testing purposes.</p>';

            // Get full html:
            $body =
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset='.strtolower(config_item('charset')).'" />
    <title>'.html_escape($subject).'</title>
    <style type="text/css">
        body {
            font-family: Arial, Verdana, Helvetica, sans-serif;
            font-size: 16px;
        }
    </style>
</head>
<body>
'.$message.'
</body>
//</html>';
            $this->load->library('M_pdf');
   $this->m_pdf->pdf->setTitle('Request for Quotation');
   $html = 'hiiiiiiiiiiiiiiiiiiiiiiiiiiiiii';
   $this->m_pdf->pdf->WriteHTML($html);
   $content=$this->m_pdf->pdf->Output('RFQ.pdf',"S");
   $result = $this->email->from('mm@jiklink.com')->to('jk@gmail.com')->subject($subject)->message($body)->attach($content, '', 'base64', '')->send();
   var_dump($result); // echo '<br />'; echo $this->email->print_debugger(); exit;
    }

1 个答案:

答案 0 :(得分:0)

   use this code.............. 
   $pdfFilePath = "PDF/RFQ.pdf";
    $html='hiiiiiiiiiiiiiii';
    //load mPDF library
    $this->load->library('m_pdf');
    //generate the PDF from the given html
    $this->m_pdf->pdf->WriteHTML($html);
    //download it.
    ob_clean(); 
    $this->m_pdf->pdf->Output($pdfFilePath,'F');


    $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => 'Email', 
      'smtp_pass' => 'Password', 
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE
    );
      $this->load->helper('path');
      $this->load->library('email', $config);
      $this->email->set_newline("\r\n");
      $this->email->from('Email');
      $this->email->to('email');
      $this->email->subject('Subject');
      $this->email->attach($pdfFilePath);
      $this->email->send();