Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script on email?

Status
Not open for further replies.

SpeedDemon

Programmer
Jan 1, 2001
70
GB
Hi, id like to run a php script as an email arrives in a mailbox?

Is this possoible, can I do it?

Setting a flag or soething similar?

Thanks.
 
I don't know how you would set up a flag per say, because mail boxes don't run code, they just accumulate mail waiting for someone to grab it.

What you can do is to use the IMAP functions of PHP to retrieve a mail from either a POP3 server or a NNTP mail server. If the script that did this ran every x minutes, for example, essentially you have your flag.

I believe that the IMAP module has to be installed at compile time, so you should check your php configuration to ensure that you have support.

the following php script will show you how your php is configured:

<?

echo PHP_INFO();

?>

look at the section called 'configure command'. if you have the switch --with-imap then you are good to go! otherwise you will need to compile again

heres some sample code that shows you how to open a mailbox using imap, listing all messages headers

<?php

$username=&quot;yourusername&quot;;
$password=&quot;yourpass&quot;;

$mailserver = &quot;{localhost/imap}&quot;;
$link = imap_open($mailserver, $username, $password);
$headers = imap_headers($link);

for ($x=1; $x <= count($headers); $x++) {

$idx = $x-1;
echo &quot;<a href=\&quot;theviewmessagepage.php?num=$x\&quot;>$headers[$idx]</a><br>&quot;;

}

?>

Andres Jugnarain
Wireless Editor
 
thanks for the reply.

I already have a system when orders are sent via email and a php application gets the emails, parses them out and puts the correct data into a mysql database.

However, to do this I have to login to my web based control panel and click a button, the script must run in a web browser.

Currently this system works fine. However, we will be upgrading our services (we are an sms logo/ringtones site) so that users can send ringtones / logos directly to their phones. I want the process to run say every 10 minutes so that a users order is with them in a very short space of time.

The process goes like this:

1) The user makes a product choice.
2) They ring a telephone number
3) An order email in a generic format is sent to our system ready to be picked up and processed.
4) The order is processed and sent to the user automatically.

Now, I can do all of this BUT like I said, i have to be logged into the control panel and do it via a web based system. This means that unless im logged in, users cant be sent orders and have to wait until i return. And I have a full time job, so I cant really do this :)

Therefore, i though to put everything into a cron tab, however I cant as I get many errors. I can have any print or echo statements, however the SMS server I use to send orders sends back http headers depending on if the sms has been sent etc etc. How can I over come this problem?

I have a dedicted server. I was thinking (and well, its a crap idea but it might work :) ) to launch a web browser on the server terminal, the http page loaded could then simply refresh every 10 minutes. This would allow me to over come these problems, however it seems like a very bad way of going about things,

I look forward to your replies.
 
hmmmm.... so if I am clear, the problem occurs when your sms server is invoked, and then tries to return a http header and html confirmation message to confirm that the ringtone or logo has been sent or not sent? what happens at this point?

ps. have you tried using 3G lab's/ kannels open source wap and sms gateway?





Andres Jugnarain
Wireless Editor
 
ah. something just came to mind. i have a little php script that i use, run by the crontab, that opens a webpage on remote http server, and then saves the page on my server.

presumably when this opens the page headers are involved, but the script doesn't fail.

the file that the crontab runs looks like this: (uses the php cgi method, as opposed to apache module)

/usr/bin/php -f /path/to/the/php/script.php

the php file looks like this

<?
$file = &quot;$fd = fopen($file);

## at this point i read the contents of the file and play
## about with it
## but by this point your web page has already been executed
## activating your sms service
## so either close the file pointer, or return its contents
## which will be the success or error message
## to your email address, for example

$contents=fread($fd,9999);

## $contents now contains the info on your page

fclose($fd);

hope that helps Andres Jugnarain
Wireless Editor
 
hi again, thanks for reply.

i'll pass it onto the programmer.
 
SpeedDemon, can you direct me to any resources in learning how to send ringtones? I am thinking about starting a ringtone site, but have no clue where to begin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top