Welcome Guest, Not a member yet? Register   Sign In
How to make email piping code work in CI controller
#1

[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
#2

[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
#3

[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




Theme © iAndrew 2016 - Forum software by © MyBB