Attach image to mail Codeigniter

0

I am trying to attach several images to the body of an email, however when the mail arrives the same image is shown on the body.

This is the script I'm using to scan the array images.

foreach ($attachment as $key => $value) {
        $inlineFIle = $this->email->attach( $_SERVER["DOCUMENT_ROOT"] .'/'. $value->directorio . $value->nombre_archivo, 'inline');
        $cid = $this->email->attachment_cid($inlineFIle);
        $body .= "<img src='cid:". $cid ."' alt='picture' />";
}

If for example, I remove the line from the body, attach all the images correctly to the email, but without showing them inside the body of the message.

Any ideas?

Thanks!

    
asked by jmrtn 29.08.2017 в 18:17
source

1 answer

1

I think the error is that you're passing the attachment_action () function response value to the attachment_cid () function.

The attach () function according to the documentation returns:

Returns:
CI_Email instance (method chaining)

Return type:
CI_Email

link

To the attachment_cid () function you have to pass the path and file name:

foreach ($attachment as $key => $value) 
{   
    $archivo = $_SERVER["DOCUMENT_ROOT"] .'/'. $value->directorio . $value->nombre_archivo
    $this->email->attach( $archivo, 'inline');
    $cid = $this->email->attachment_cid($archivo);
    $body .= "<img src='cid:". $cid ."' alt='picture' />";
}

I hope it works for you! =)

    
answered by 07.09.2017 / 17:30
source