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

$this->email->from('[email protected]', 'vignesh');
$this->email->subject('Email Test with attachment');
$this->email->message('Testing the email class IN CODEIGNITER');

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

  • 1
    NP, but it was actually originally stealthyninja's edit. I just reworded his edit a little and then approved the change. ;-P Commented Dec 24, 2012 at 14:19

1 Answer 1


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

$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


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


Not the answer you're looking for? Browse other questions tagged or ask your own question.