Forum Moderators: coopster

Message Too Old, No Replies

Automatically convert emails to web pages.

Can PHP and MySql do this?

         

tgo2002

5:12 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



I've been using PHP for a while now and it seems like it will do just about anything I can dream up. But I would like to be able to add entries to an online travel diary by sending an email. Often I have just the text messaging on my phone, which has no web capabilities. Is it possible to send email messages directly to a MySql database? Once it's in the database I can figure out the PHP part, but getting the messages into the database directly from email seems to be the tricky part.

hakre

5:15 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi tgo2002,

it's not possible to send an email directly into mysql BUT if your server has got cronjobs, you can create a script that checks a mailacc of yours and if an email is in, it will insert the text into your database. but you will need cronjob for that.

tgo2002

5:20 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



Would phpinfo() tell me whether that's available? I just looked at it and didn't find anything like that.

hakre

5:22 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



no phpinfo() is not aware of cronjobs. that's a feature of *nix operating systems. just ask your hoster if it's available and if yes, ask him how you can use it.

tgo2002

5:23 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



OK, thanks for your quick reply.

caspita

5:23 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



Just to clarify. A cronn job is not a feature of PHP, it is a facility of the server OS (linux, etc), the idea of the cron job is that you can schedule a task (like php running a .php script) every x minutes, hours, days , etc... then once the php is running it is all yours.

Nutter

5:30 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



For that matter, couldn't the PHP page access the mailbox file directly, assuming permissions were correct? That way you wouldn't have to worry about cron. Maybe open the mailbox and import anything from it into MySQL every time the user logs in?

I think (in that I've read about it, but never done it) that it's possible to pipe incoming emails to a PHP script. If it works the way it sounds, every time an email comes in it goes through the script instead of to the mailbox.

- Ryan

jatar_k

5:39 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



also take a look at Procmail to process the emails. We used procmail to insert into mysql for use in phpbb.

I can't seem to get to [procmail.org...] at the moment

andye

5:42 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



There are some SMS to HTTP gateways / APIs out there now, that would be another approach.

Andy.

hakre

5:42 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe open the mailbox and import anything from it into MySQL every time the user logs in?

if no cronjobs are available, this is indeed quite a good option to ensure the mailbox is even checked from time to time. but this is not a professional solution at all, because you can not say when a visitor is passing by.

hakre

9:04 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



there is a complete pop3 solution available (comments in within the source in german language) for download [faq.1und1.com]

that script checks the mailbox and you can give even commands with each email to update existing news and to delete them. this is only the php/pop3 part, nothing with cronjobs or a special mailserver configuration (like the procmail ideas here which do look indeed very cool).

haryanto

1:41 am on Feb 19, 2005 (gmt 0)

10+ Year Member



You have to look up on piping.

I have created a PHP script to listen to emails.
The moment an email arrives to the server, it generates an HTML page containing the email contents.

I have also tried inserting the email content to MySQL.

You have 2 options.
1. Email piping.
2. Cronning an imap function to check email every now and then.

NickCoons

2:32 am on Feb 19, 2005 (gmt 0)

10+ Year Member



I think piping is the way to go. Most MTAs (Sendmail, Postfix, Exim, etc) can be configured this way. That is, when a particular email address receives a message, instead of the message behind handled like it normally would be on the server (i.e. stored in a local maildrop), it is "piped" elsewhere, for instance, to a PHP script.

So in this instance, the email (in its entirety with heads and all) would be sent as a parameter to the PHP script and could be handled accordingly. No need to run a cron job or build/install any code that would check a POP3 or IMAP account. This is probably as close as you can get to directly emailing a PHP script.. so your PHP script in essence becomes the direct recipient of the email.

hakre

7:32 am on Feb 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i had problems to execute php files directly in the shell. are there any tricks? i guess i will have the same problems while using pipes. but i want to check that out because it seems very useable for me.

NickCoons

9:44 pm on Feb 19, 2005 (gmt 0)

10+ Year Member



hakre,

You can run it like a Perl script. The top of the file looks like this:

#!/path/to/php -q

And then, of course, surround your code with <?php and?>. Also, make sure to make the script executable (chmod 755).

ergophobe

11:13 pm on Feb 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There's an evolt.org tutorial on Incoming Mail and PHP [evolt.org]

That might be useful especially since it has a lot of user comments added in as well.

hakre

12:20 am on Feb 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks folks. finally it worked! it's just the same like perl, i just did not get it. anyway, now i don't need lynx any longer and can call the scripts directly :)