CodeIgniter Forums

Full Version: How to make email piping code work in CI controller
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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

El Forum

[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

El Forum

[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