Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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');
share|improve this question

closed as off topic by John Conde Dec 24 '12 at 14:24

Questions on Webmasters Stack Exchange are expected to relate to webmastering within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
@Lese Thank you for fixing grammar issues –  Vignesh Dec 24 '12 at 14:12
1  
NP, but it was actually originally stealthyninja's edit. I just reworded his edit a little and then approved the change. ;-P –  Lèse majesté Dec 24 '12 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

$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.

share|improve this answer
1  
Thank you @stealthninja –  Vignesh Dec 24 '12 at 14:27

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