无法使用codeigniter中的弹性电子邮件API发送带有附件的电子邮件

y1aodyip  于 2023-03-21  发布在  其他
关注(0)|答案(1)|浏览(221)

我已经使用TCPDF生成PDF,它工作正常。我尝试发送电子邮件与PDF生成作为附件的电子邮件。电子邮件发送没有附件。请帮助更正下面的代码,以确保附件也在电子邮件中发送。
payment.php

$attachment =  $pdf->Output('example_001.pdf', 'D');
$attachment = base64_encode($attachment);

$attachmentlink = 'http://localhost/cfac/resources/invoices/example_001.pdf';

$inputdata['firstname']="abc";
$inputdata['ename']="Event Name";
$inputdata['tno']="tno:232423";
$inputdata['amount']="10000rs";
$inputdata['edetails']="EDetails";
$inputdata['startdate']="Start Date";
$inputdata['enddate']="End Date";
$template='xyz';

$emailid="xxx@gmail.com";
// email helper to send email
$this->load->helper ('email');

        $filename = "example_001.pdf";
        $file_name_with_full_path = base_url()."resources/inv/example_001.pdf";
        $filetype = "application/pdf";

        $attachmentFiles = array('http://localhost/cfac/resources/inv/example_001.pdf');

        send_email($emailid,$inputdata,$template, $attachmentFiles );

emailhelper.php
emailconfig详细信息已设置为配置文件中的值。

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('send_email'))
{

function send_email($emailid,$inputdata,$template,$attachmentFiles )
{

    $CI =& get_instance();
    $CI->load->config('emailcofnig');
    //$ci->email->attach( 'http://localhost/cfac/resources/inv/example_001.pdf');

    $emailconfig=$CI->config->item('elasticemail');

    $url=$emailconfig['url'];

    $filename = "example_001.pdf";
    $file_name_with_full_path = "http://localhost/cfac/resources/invoices/example_001.pdf";
    $filetype = "application/pdf";

    $email = array(
        'from' => $emailconfig['fromemailid'],
        'fromName' => $emailconfig['from'],
        'apikey' => $emailconfig['apikey'],
        'subject' => $emailconfig['defaultsubject'],
        'to' => $emailid,
        'isTransactional' => true,
        'template' => $templatename,
        'file_1' => new CurlFile($file_name_with_full_path, $filetype, $filename)
        );

        foreach($inputdata as $key => $value)
        {
            $email['merge_'.$key] = $value;
        }


    // use key 'http' even if you send the request to https://...
    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
            'method'  => 'POST',
            'content' => http_build_query($email)
        )
    );

    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    if ($result === FALSE) { /* Handle error */ return 0;}

    }
}

?>
wljmcqd8

wljmcqd81#

使用此代码:

$ci = get_instance();
                $ci->load->library('email');
                $config['protocol'] =  $ci->config->item('protocol');
                $config['smtp_host'] = $ci->config->item('smtp_host');
                $config['smtp_port'] = $ci->config->item('smtp_port');
                $config['smtp_user'] = $ci->config->item('smtp_user');
                $config['smtp_pass'] = $ci->config->item('smtp_pass');
                $config['charset'] =  $ci->config->item('charset');
                $config['mailtype'] = $ci->config->item('mailtype');
                $config['newline'] = "\r\n";

                $ci->email->initialize($config);
                $ci->email->from("no-reply@nirbachon.net", $ci->config->item('smtp_user_display_name'));
                $ci->email->to($email);
                $ci->email->cc($cc);
                $ci->email->bcc($bcc);
                $ci->email->reply_to("no-reply@nirbachon.net", $ci->config->item('smtp_user_display_name'));
                $ci->email->subject($subject);
                if($attachment != null){
                  $ci->email->attach($attachment);
                }
                $ci->email->message($email_body);
                $ci->email->send();

相关问题