469,306 Members | 2,398 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Using Php to receive - read email

Can anyone point me in the right direction? I want to use Php to
automate confirmation of someone joining an email list by them replying
to an email (so they don't have to have a browser?).

I will probably use a hyperlink with a unique ID, but I also want to
know how to go about reading from a mailbox with Php so I can use an
email reply method, too.

I'm having trouble finding any kind of tutorial. From the bit of
searching I've done, it appears I need to use an IMAP client and the
IMAP functions (I've no experience with using IMAP, but could learn).

Can I use Php functions to read email from a POP3 mailbox?

Does anyone know of any tutorials or helpful web sites that might
explain what I need to do?

Thanks in Advance.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jul 17 '05 #1
12 8436
Chuck Anderson <we************@seemy.sig> wrote in message news:<cnn3c.529026$na.1267192@attbi_s04>...
Can anyone point me in the right direction? I want to use Php to
automate confirmation of someone joining an email list by them replying
to an email (so they don't have to have a browser?).

I will probably use a hyperlink with a unique ID, but I also want to
know how to go about reading from a mailbox with Php so I can use an
email reply method, too.

I'm having trouble finding any kind of tutorial. From the bit of
searching I've done, it appears I need to use an IMAP client and the
IMAP functions (I've no experience with using IMAP, but could learn).

Can I use Php functions to read email from a POP3 mailbox?

Does anyone know of any tutorials or helpful web sites that might
explain what I need to do?


1. forward file <http://groups.google.com/groups?selm=vppnnssuq4p394%40corp.supernews.com>
2. <http://in2.php.net/imap> Manual & user notes

--
"I don't believe in the God who doesn't give me food, but shows me
heaven!"--Swami Vivekanandha
Email: rrjanbiah-at-Y!com
Jul 17 '05 #2
R. Rajesh Jeba Anbiah wrote:
Chuck Anderson <we************@seemy.sig> wrote in message news:<cnn3c.529026$na.1267192@attbi_s04>...
Can anyone point me in the right direction? I want to use Php to
automate confirmation of someone joining an email list by them replying
to an email (so they don't have to have a browser?).

I will probably use a hyperlink with a unique ID, but I also want to
know how to go about reading from a mailbox with Php so I can use an
email reply method, too.

I'm having trouble finding any kind of tutorial. From the bit of
searching I've done, it appears I need to use an IMAP client and the
IMAP functions (I've no experience with using IMAP, but could learn).

Can I use Php functions to read email from a POP3 mailbox?

Does anyone know of any tutorials or helpful web sites that might
explain what I need to do?


1. forward file <http://groups.google.com/groups?selm=vppnnssuq4p394%40corp.supernews.com>
2. <http://in2.php.net/imap> Manual & user notes

I see. I can use the "IMAP" functions for POP3. Thanks for the pointer.
I can begin experimenting now.

(The first link is how I can have a new email trigger the event. That
will also be most useful.)

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jul 17 '05 #3
Let me ask this, Are you trying to have PHP parse an email when it arrives?

If so, differnt aproach than trying to pop a box.

Also if you are using, say redhat linux:

in /etc/aliases file add this line:

alias-phpparse: "| /etc/smrsh/phpparser.php"
then in /etc/smrsh/ create a script called phpparser.php and it should look
like this:
(make sure the #!/.... is the very first line!)

#!/usr/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin", "r");

// we read each line of the incoming email
while (!feof($fd))
{
$inData = fgets($fd, 1024);
$inData = trim($inData);

// we loop over and over untill we read each line
// proccess email here, $inData will contain 1 line from the email
on each pass
}
fclose($fd);
?>
--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Chuck Anderson" <we************@seemy.sig> wrote in message
news:cnn3c.529026$na.1267192@attbi_s04...
Can anyone point me in the right direction? I want to use Php to
automate confirmation of someone joining an email list by them replying
to an email (so they don't have to have a browser?).

I will probably use a hyperlink with a unique ID, but I also want to
know how to go about reading from a mailbox with Php so I can use an
email reply method, too.

I'm having trouble finding any kind of tutorial. From the bit of
searching I've done, it appears I need to use an IMAP client and the
IMAP functions (I've no experience with using IMAP, but could learn).

Can I use Php functions to read email from a POP3 mailbox?

Does anyone know of any tutorials or helpful web sites that might
explain what I need to do?

Thanks in Advance.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************

Jul 17 '05 #4
so sorry, I forgot 1 thing, add this line to /etc/mail/virtusertable

an***@yourdomain.com alais-phpparser

then rebuild the map with
cd /etc/mail
makemap hash virtusertable < virtusertable

--
Mike Bradley
http://www.gzentools.com -- free online php tools
"CountScubula" <me@scantek.hotmail.com> wrote in message
news:H4*****************@newssvr29.news.prodigy.co m...
Let me ask this, Are you trying to have PHP parse an email when it arrives?
If so, differnt aproach than trying to pop a box.

Also if you are using, say redhat linux:

in /etc/aliases file add this line:

alias-phpparse: "| /etc/smrsh/phpparser.php"
then in /etc/smrsh/ create a script called phpparser.php and it should look like this:
(make sure the #!/.... is the very first line!)

#!/usr/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin", "r");

// we read each line of the incoming email
while (!feof($fd))
{
$inData = fgets($fd, 1024);
$inData = trim($inData);

// we loop over and over untill we read each line
// proccess email here, $inData will contain 1 line from the email on each pass
}
fclose($fd);
?>
--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Chuck Anderson" <we************@seemy.sig> wrote in message
news:cnn3c.529026$na.1267192@attbi_s04...
Can anyone point me in the right direction? I want to use Php to
automate confirmation of someone joining an email list by them replying
to an email (so they don't have to have a browser?).

I will probably use a hyperlink with a unique ID, but I also want to
know how to go about reading from a mailbox with Php so I can use an
email reply method, too.

I'm having trouble finding any kind of tutorial. From the bit of
searching I've done, it appears I need to use an IMAP client and the
IMAP functions (I've no experience with using IMAP, but could learn).

Can I use Php functions to read email from a POP3 mailbox?

Does anyone know of any tutorials or helpful web sites that might
explain what I need to do?

Thanks in Advance.

--
*****************************
Chuck Anderson . Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************


Jul 17 '05 #5
CountScubula wrote:
Let me ask this, Are you trying to have PHP parse an email when it arrives?

That's what I'd like to do.
If so, differnt aproach than trying to pop a box.

I assume you are talking about having new a new email trigger an event
(parse the email), and that I could still do the same manually or with a
task scheduler using IMAP functions.

Yes?
Also if you are using, say redhat linux:

My site is on a Linux server, but I don't even have shell access. I'll
keep your suggestion, though, because I *can* get shell access. It
sounds like what I want to do is no simple thing (at least for me).
in /etc/aliases file add this line:

alias-phpparse: "| /etc/smrsh/phpparser.php"
then in /etc/smrsh/ create a script called phpparser.php and it should look
like this:
(make sure the #!/.... is the very first line!)\

Gotcha - tells the php "interpreter" to read the following lines.
#!/usr/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin", "r");

// we read each line of the incoming email
while (!feof($fd))
{
$inData = fgets($fd, 1024);
$inData = trim($inData);

// we loop over and over untill we read each line
// proccess email here, $inData will contain 1 line from the email
on each pass
}
fclose($fd);
?>
That added line in your next post is quite key to understanding how this
works, right?
"an***@yourdomain.com alias-phpparser"

Thanks for the help.
--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Chuck Anderson" <we************@seemy.sig> wrote in message
news:cnn3c.529026$na.1267192@attbi_s04...
Can anyone point me in the right direction? I want to use Php to
automate confirmation of someone joining an email list by them replying
to an email (so they don't have to have a browser?).

I will probably use a hyperlink with a unique ID, but I also want to
know how to go about reading from a mailbox with Php so I can use an
email reply method, too.

I'm having trouble finding any kind of tutorial. From the bit of
searching I've done, it appears I need to use an IMAP client and the
IMAP functions (I've no experience with using IMAP, but could learn).

Can I use Php functions to read email from a POP3 mailbox?

Does anyone know of any tutorials or helpful web sites that might
explain what I need to do?

Thanks in Advance.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************


--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jul 17 '05 #6
I guess I should have exmplained how it works.

This is a way to have an email, upon arrival, get passed to your php script
instead of proccessed and put into a mailbox. if you wish to save a copy or
have it end up in the correct mailbox, then you need to do that yourself.

This is good for autoreplies, or email request systems (like fax back)
this part
add line to /etc/mail/virtusertable
an***@yourdomain.com alias-phpparser

then rebuild the map with
cd /etc/mail
makemap hash virtusertable < virtusertable
adds an email address to the mail server, so anything comming to that email
address would go to user alias-phpparser (since this file only maps email
address to user accounts we map to an alias user)

here we add the alias user, in, well /etc/alias file, this file allows alias
user accounts, these can map to other users, single or more, or can forward
mail to a script. generaly the scripts sit in /etc/smrsh
so in /etc/alias file we add the line
alias-phpparser: "| /etc/smrsh/phpparser.php"
this tells the box the alias-phpparser is an alias, and to filter the mail
to the script

then in /etc/smrsh/ we put scripts that get passed emails from sendmail,
smrsh is SendMail Retricted SHell, this should be the only dir that sendmail
should be allowed to run scripts.
so, in /etc/smrsh/ dir we add the script
alias-phpparser.php
also this file needs to be chmod 755 #!/usr/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin", "r");

// we read each line of the incoming email
while (!feof($fd))
{
$inData = fgets($fd, 1024);
$inData = trim($inData);

// we loop over and over untill we read each line
// proccess email here, $inData will contain 1 line from the email
on each pass

}
fclose($fd);
?>

--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Chuck Anderson" <we************@seemy.sig> wrote in message
news:f584c.10276$i76.158609@attbi_s03... CountScubula wrote:
Let me ask this, Are you trying to have PHP parse an email when it arrives?

That's what I'd like to do.
If so, differnt aproach than trying to pop a box.

I assume you are talking about having new a new email trigger an event
(parse the email), and that I could still do the same manually or with a
task scheduler using IMAP functions.

Yes?
Also if you are using, say redhat linux:

My site is on a Linux server, but I don't even have shell access. I'll
keep your suggestion, though, because I *can* get shell access. It
sounds like what I want to do is no simple thing (at least for me).
in /etc/aliases file add this line:

alias-phpparse: "| /etc/smrsh/phpparser.php"
then in /etc/smrsh/ create a script called phpparser.php and it should looklike this:
(make sure the #!/.... is the very first line!)\

Gotcha - tells the php "interpreter" to read the following lines.
#!/usr/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin", "r");

// we read each line of the incoming email
while (!feof($fd))
{
$inData = fgets($fd, 1024);
$inData = trim($inData);

// we loop over and over untill we read each line
// proccess email here, $inData will contain 1 line from the emailon each pass
}
fclose($fd);
?>

That added line in your next post is quite key to understanding how this
works, right?
"an***@yourdomain.com alias-phpparser"

Thanks for the help.
--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Chuck Anderson" <we************@seemy.sig> wrote in message
news:cnn3c.529026$na.1267192@attbi_s04...
Can anyone point me in the right direction? I want to use Php to
automate confirmation of someone joining an email list by them replying
to an email (so they don't have to have a browser?).

I will probably use a hyperlink with a unique ID, but I also want to
know how to go about reading from a mailbox with Php so I can use an
email reply method, too.

I'm having trouble finding any kind of tutorial. From the bit of
searching I've done, it appears I need to use an IMAP client and the
IMAP functions (I've no experience with using IMAP, but could learn).

Can I use Php functions to read email from a POP3 mailbox?

Does anyone know of any tutorials or helpful web sites that might
explain what I need to do?

Thanks in Advance.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************


--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************

Jul 17 '05 #7
CountScubula wrote:
I guess I should have exmplained how it works.

This is a way to have an email, upon arrival, get passed to your php script
instead of proccessed and put into a mailbox.
That *is* what I ultimately want to do.
This is good for autoreplies, or email request systems (like fax back)

Or to automate subscription to a mailing list.

this part
add line to /etc/mail/virtusertable
an***@yourdomain.com alias-phpparser

then rebuild the map with
cd /etc/mail
makemap hash virtusertable < virtusertable


adds an email address to the mail server, so anything comming to that email
address would go to user alias-phpparser (since this file only maps email
address to user accounts we map to an alias user)

here we add the alias user, in, well /etc/alias file, this file allows alias
user accounts, these can map to other users, single or more, or can forward
mail to a script. generaly the scripts sit in /etc/smrsh
so in /etc/alias file we add the line
alias-phpparser: "| /etc/smrsh/phpparser.php"


this tells the box the alias-phpparser is an alias, and to filter the mail
to the script

then in /etc/smrsh/ we put scripts that get passed emails from sendmail,
smrsh is SendMail Retricted SHell, this should be the only dir that sendmail
should be allowed to run scripts.
so, in /etc/smrsh/ dir we add the script
alias-phpparser.php
also this file needs to be chmod 755

#!/usr/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin", "r");

// we read each line of the incoming email
while (!feof($fd))
{
$inData = fgets($fd, 1024);
$inData = trim($inData);

// we loop over and over untill we read each line
// proccess email here, $inData will contain 1 line from the email
on each pass

}
fclose($fd);
?>

--
Mike Bradley
http://www.gzentools.com -- free online php tools
"Chuck Anderson" <we************@seemy.sig> wrote in message
news:f584c.10276$i76.158609@attbi_s03...
CountScubula wrote:
>Let me ask this, Are you trying to have PHP parse an email when itarrives? >
>

That's what I'd like to do.
>If so, differnt aproach than trying to pop a box.
>
>

I assume you are talking about having new a new email trigger an event
(parse the email), and that I could still do the same manually or with a
task scheduler using IMAP functions.

Yes?
>Also if you are using, say redhat linux:
>
>

My site is on a Linux server, but I don't even have shell access. I'll
keep your suggestion, though, because I *can* get shell access. It
sounds like what I want to do is no simple thing (at least for me).
>in /etc/aliases file add this line:
>
>alias-phpparse: "| /etc/smrsh/phpparser.php"
>
>
>then in /etc/smrsh/ create a script called phpparser.php and it shouldlook >like this:
>(make sure the #!/.... is the very first line!)\
>
>

Gotcha - tells the php "interpreter" to read the following lines.
>#!/usr/bin/php -q
><?php
> // read from stdin
> $fd = fopen("php://stdin", "r");
>
> // we read each line of the incoming email
> while (!feof($fd))
> {
> $inData = fgets($fd, 1024);
> $inData = trim($inData);
>
> // we loop over and over untill we read each line
> // proccess email here, $inData will contain 1 line from theemail >on each pass
>
>
> }
> fclose($fd);
>?>
>
>
>

That added line in your next post is quite key to understanding how this
works, right?
"an***@yourdomain.com alias-phpparser"

Thanks for the help.
>--
>Mike Bradley
>http://www.gzentools.com -- free online php tools
>"Chuck Anderson" <we************@seemy.sig> wrote in message
>news:cnn3c.529026$na.1267192@attbi_s04...
>> Can anyone point me in the right direction? I want to use Php to
>> automate confirmation of someone joining an email list by them replying
>> to an email (so they don't have to have a browser?).
>>
>> I will probably use a hyperlink with a unique ID, but I also want to
>> know how to go about reading from a mailbox with Php so I can use an
>> email reply method, too.
>>
>> I'm having trouble finding any kind of tutorial. From the bit of
>> searching I've done, it appears I need to use an IMAP client and the
>> IMAP functions (I've no experience with using IMAP, but could learn).
>>
>> Can I use Php functions to read email from a POP3 mailbox?
>>
>> Does anyone know of any tutorials or helpful web sites that might
>> explain what I need to do?
>>
>> Thanks in Advance.
>>

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Jul 17 '05 #8
"CountScubula" <me@scantek.hotmail.com> wrote in message news:<h5*******************@newssvr29.news.prodigy .com>...
I guess I should have exmplained how it works.

This is a way to have an email, upon arrival, get passed to your php script
instead of proccessed and put into a mailbox. if you wish to save a copy or
have it end up in the correct mailbox, then you need to do that yourself.

This is good for autoreplies, or email request systems (like fax back)
this part
add line to /etc/mail/virtusertable
an***@yourdomain.com alias-phpparser

then rebuild the map with
cd /etc/mail
makemap hash virtusertable < virtusertable


adds an email address to the mail server, so anything comming to that email
address would go to user alias-phpparser (since this file only maps email
address to user accounts we map to an alias user)

here we add the alias user, in, well /etc/alias file, this file allows alias
user accounts, these can map to other users, single or more, or can forward
mail to a script. generaly the scripts sit in /etc/smrsh
so in /etc/alias file we add the line
alias-phpparser: "| /etc/smrsh/phpparser.php"


this tells the box the alias-phpparser is an alias, and to filter the mail
to the script


I'm not a *nix expert. But, this link
<http://forums.devshed.com/t64071/s.html> says forward file is better
than aliases file. Do you have any comment on it?

--
"I don't believe in the God who doesn't give me food, but shows me
heaven!"--Swami Vivekanandha
Email: rrjanbiah-at-Y!com
Jul 17 '05 #9
Well to use a forward file, you must add a user to the linux box, so then
there actualy is a new user account. you can leave it as no password so no
one uses the account.

Then in that users /home/dir you create a '.forward' file, and stick in
email addresses, one per line. Sorta like a mini mailing list.

Draw backs to me, are for simple 1,2,3 email forwards this consumes a
userid, and requires a user in the /home

On my mail servers, there are only a hand full of /home/dir's and they are
for me, and whom ever is assisting me, the general users have no /home/dir
on any of my servers

Now the alias file, is as it is called, but for user accounts, you create
alias user names, and then point to real users (not email address),
although, it can forward to email addresses.
these are valid entries

owner: root
admins: root, john, jane, jo*@otherplace.com
some-script: root, "|/etc/smrsh/script.php"
filter: "|/etc/smrsh/filter.php"
Then is the /etc/virtusertable file, this file maps email addresses to user
accounts. you can also forward email from here.
here are valid entries:

jo**@mydomain.com john
in**@mydomain.com john

no******@mydomain.com filter

sa*@domain.com sa*@otherdomain.com

@domain.com error 550: Sorry, invalid user.
So IMHO, I use as follows:
/etc/alias to set up filter scripts.
/etc/virtusertable to map emails to user names
..forward for mini distribution lists
--
Mike Bradley
http://www.gzentools.com -- free online php tools
"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> wrote in message
news:ab**************************@posting.google.c om...
"CountScubula" <me@scantek.hotmail.com> wrote in message

news:<h5*******************@newssvr29.news.prodigy .com>...
I guess I should have exmplained how it works.

This is a way to have an email, upon arrival, get passed to your php script instead of proccessed and put into a mailbox. if you wish to save a copy or have it end up in the correct mailbox, then you need to do that yourself.
This is good for autoreplies, or email request systems (like fax back)
this part
add line to /etc/mail/virtusertable
an***@yourdomain.com alias-phpparser

then rebuild the map with
cd /etc/mail
makemap hash virtusertable < virtusertable


adds an email address to the mail server, so anything comming to that email address would go to user alias-phpparser (since this file only maps email address to user accounts we map to an alias user)

here we add the alias user, in, well /etc/alias file, this file allows alias user accounts, these can map to other users, single or more, or can forward mail to a script. generaly the scripts sit in /etc/smrsh
so in /etc/alias file we add the line
alias-phpparser: "| /etc/smrsh/phpparser.php"


this tells the box the alias-phpparser is an alias, and to filter the mail to the script


I'm not a *nix expert. But, this link
<http://forums.devshed.com/t64071/s.html> says forward file is better
than aliases file. Do you have any comment on it?

--
"I don't believe in the God who doesn't give me food, but shows me
heaven!"--Swami Vivekanandha
Email: rrjanbiah-at-Y!com

Jul 17 '05 #10
On 2004-03-12, CountScubula <me@scantek.hotmail.com> wrote:
Well to use a forward file, you must add a user to the linux box, so then
there actualy is a new user account. you can leave it as no password so no
one uses the account.


procmail is your friend ;)

--
http://home.mysth.be/~timvw
Jul 17 '05 #11
"Tim Van Wassenhove" <eu**@pi.be> wrote in message
news:c2*************@ID-188825.news.uni-berlin.de...
On 2004-03-12, CountScubula <me@scantek.hotmail.com> wrote:
Well to use a forward file, you must add a user to the linux box, so then there actualy is a new user account. you can leave it as no password so no one uses the account.


procmail is your friend ;)

--
http://home.mysth.be/~timvw

I agree with you here, and it could be simpler, one procmail entry and you
could be off and running, but I have seen to many people screw up *all* the
email on a system from a bad entry.

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #12
"CountScubula" <me@scantek.hotmail.com> wrote in message news:<zm*****************@newssvr27.news.prodigy.c om>...

<some rational explanations snipped>
So IMHO, I use as follows:
/etc/alias to set up filter scripts.
/etc/virtusertable to map emails to user names
.forward for mini distribution lists


Indeed a very useful post.

--
"Democracy: Where all citizens are politicians and all politicians are citizens"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by siliconmike | last post: by
13 posts views Thread by Eirik WS | last post: by
reply views Thread by palomine1234 | last post: by
3 posts views Thread by Erik Johnson | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.