Mobile app version of vmapp.org
Login or Join
Barnes591

: Add email attachments by URL in CodeIgniter I tried this code to attach a file in CI. This is working: $this->load->library('email'); $this->email->from('me@mymail.com', 'vignesh'); $this->email->subject('Email

@Barnes591

Posted in: #Codeigniter #Email #Php

I tried this code to attach a file in CI. This is working:

$this->load->library('email');
$this->email->from('me@mymail.com', 'vignesh');
$this->email->subject('Email Test with attachment');
$this->email->message('Testing the email class IN CODEIGNITER');
$this->email->attach('/path/to/attachment1.jpg');
$this->email->send();


But I want to attach a file from an external URL:

$this->email->attach('http://mydomain.in/path/to/attachment1.jpg');

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Barnes591

1 Comments

Sorted by latest first Latest Oldest Best

 

@Shelley277

No, it isn't possible, you'll need to download the file first. Using Phil Sturgeon's cURL library for CodeIgniter you should be able to get the file

$this->load->library('curl');
$img = $this->curl->simple_get('http://mydomain.in/path/to/attachment1.jpg');
$filename = basename($img);
write_file("./upload/path/" . $filename, $img);


and then include it

$this->email->attach('/path/to/attachment1.jpg');


You could later build in caching to check if the file was already downloaded / exists so it doesn't need to fetch it again.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme