Dynamically calling data in mail and pdf function in codeigniter PHP

老子叫甜甜 提交于 2019-12-20 06:28:05

问题


I am working on a project where client want to send a PDF copy to vendor as soon as they mark order as receive .

i have successfully export the PDF of particular order, i called the mail function in the same function , so that whenever PDF is generated a mail is sent with the attached PDF which is generated from html using mpdf library ..

the problems i am facing are - >

  1. the name of the PDF file in mpdf is static.. like xyz.pdf. when i write "xyz".$order['order_id']".pdf" it doesn't work .. i also tried saving it to a variable and calling it. i want to save each PDF with its order id. i tried to echo order id . but its giving null value in the current function . but showing values everywhere in the controller.

  2. only manually entry of mail id is working . .for ex. if i write xyz@abc.comit sends the mail to that mail id.. but if i write there $orders['vendor_email']; its not working .

  3. in subject if i write "xyzxyz" , mail sent by this subject.. but if i write - "xyzzyz".$orders[order_id] for showing order id with string in subject.. then its sending mail with no subject.

here is my code . please review and help me.

-- Mail function in global_helper.php

 function sendEmail($email, $subject, $message,$bcc='',$cc='',$from='',$attach=''){   //DebugBreak();
    $tobj =&get_instance();
    $tobj->load->library('email');
    $tobj->email->clear();

    $subject_text = ($tobj->session->userdata('company_name') != '') ? $tobj->session->userdata('company_name') : "Udaan";

    $config=array(
    'charset'=>'utf-8',
    'wordwrap'=> TRUE,
    'mailtype' => 'html'
    );

    $tobj->email->initialize($config);

    if(!empty($from))
    $tobj->email->from($from);
    else
    $tobj->email->from('admin@xyz.com',$subject_text);
    $tobj->email->to($email);
    if(!empty($bcc))
        $tobj->email->bcc($bcc);
    if(!empty($cc))
        $tobj->email->cc($cc);
    if(!empty($attach))
        $tobj->email->attach($attach);    
    $tobj->email->subject($subject);
    $tobj->email->message($message);
    $tobj->email->send();

}

My Controller ->

function sendgrnmail($oid)
{
$order_id                     = $order['order_id'];
$this->data['company']        = $this->om->getCompanyDetails();
$this->data['company_info']   = $this->om->getCompanyDetails();
$this->data['order']          = $this->om->getOrders(array(
'order_id' => $oid
));
$this->data['order_products'] = $this->om->getOrderProducts($oid);
$this->load->library('m_pdf');
$this->data['title']       = "GRN";
$this->data['description'] = "";
$this->data['description'] = $this->official_copies;
$html                      = $this->load->view('vendor/mail_grn', $this->data, true);
// echo $html;
// die();
$pdfFilePath               = "mypdfName-" . time() . "-download.pdf";
$pdfFilePath               = FCPATH . "attach/VOGRN.pdf";
// here if i want to save file with order_id . but not working when i write $order(order_id)., even if i echo any info here its not loading in view.. other then echo $html.


$pdf = $this->m_pdf->load();
$pdf->WriteHTML($html, 2);
$pdf->Output($pdfFilePath, "F");
$message = "<strong>This is system generated mail, please do not reply on this. </strong>";
// here also i want to send dynamica text with order id and other details. but not working . like - "please contact". $order['contact_info']; //

sendEmail("maildid@domain.com", "GRN", $message, $bcc = '', $cc = 'mailidcc@domain.com', $from = '', $pdfFilePath);

// in the above sendemail function dynamic data is not loading up in mail id and subject(grn) }

来源:https://stackoverflow.com/questions/55182653/dynamically-calling-data-in-mail-and-pdf-function-in-codeigniter-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!