CodeIgniter Forums
How to make email piping code work in CI controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: How to make email piping code work in CI controller (/showthread.php?tid=25253)



How to make email piping code work in CI controller - El Forum - 12-05-2009

[eluser]Zac G.[/eluser]
Hi folks,

I am trying to use information from an email in a controller.

This is the basic code I am working with:

Code:
#!/usr/bin/php -q
<?php

$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd))
{
   $email .= fread($fd, 1024);
}
fclose($fd);
          
//Then I can do what I want with the $email variable
?>

Any suggestions on how I can add this into a controller? Or is there a better way to pipe an email straight to a controller function?

Cheers,
Zac


How to make email piping code work in CI controller - El Forum - 12-06-2009

[eluser]Jamie Rumbelow[/eluser]
Technically, that code will work (should, I haven't tested it myself) in your controller. A controller is just code like anything else, but you will have to invoke it by invoking the routing mechanism, and at the command line, this can be tricky. Also, as you're dealing with data, I'd recommend you put that code in the model rather than the controller.

Having said that a much better, more robust solution would be to setup a POP or IMAP mail server on your machine (a trivial task) and connect to that. Not only do emails persist but you've got a lot more flexibility. A good pop/imap class for CodeIgniter can be found on the Wiki.

Jamie


How to make email piping code work in CI controller - El Forum - 12-06-2009

[eluser]Zac G.[/eluser]
Hey Jamie,

I appreciate the help. I haven't worked with pulling in data from emails into an application so I am sort of stabbing around with how to do it.

This pop/gmail class looks like a much better direction to go in.

Cheers,
Zac