By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,569 Members | 1,321 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,569 IT Pros & Developers. It's quick & easy.

using php mail to forward email?

P: n/a
Hello,

us**@x.com receives an email from us**@a.com. I want to forward that
email to us**@y.com. I want the contents/header to remain intact, with
the exception of adding "X-Forwarded-For". In other words, when
us**@y.com received the email, it will be from us**@a.com, but will
contain a reference that it was forwarded by us**@x.com.

I'm piping all email destined for us**@x.com to a php script. I've seen
some very complicated examples of using the mail function and I'm unsure
how to use the mail function to do what I need. I'm relatively new to
php so any advice is appreciated.

Thank you,
Craig.
#!/usr/local/bin/php -q
<?php

// get email from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);

// forward it to us**@y.com
// ???
?>
Oct 14 '07 #1
Share this Question
Share on Google+
15 Replies


P: n/a
In our last episode, <9m*******************@news.indigo.ie>, the lovely and
talented Craig Hurley broadcast on comp.lang.php:
Hello,
us**@x.com receives an email from us**@a.com. I want to forward that
email to us**@y.com.
Why, exactly, don't you do that in your mail server? It's the right tool
for this job.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 463 days to go.
What do you do when you're debranded?
Oct 14 '07 #2

P: n/a
On Oct 14, 5:08 pm, Lars Eighner <use...@larseighner.comwrote:
In our last episode, <9mvQi.22601$j7.428...@news.indigo.ie>, the lovely and
talented Craig Hurley broadcast on comp.lang.php:
Hello,
u...@x.com receives an email from u...@a.com. I want to forward that
email to u...@y.com.

Why, exactly, don't you do that in your mail server? It's the right tool
for this job.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 463 days to go.
What do you do when you're debranded?

If I'm reading this correctly, it looks like he wants to be able to
spoof the email forward to look like the original sender sent it. I
think that if this is a legitimate question, if you aren't looking to
be, you will soon find yourself a SPAM hub. Essentially, you could
take an email from person1, change the contents, and send it to
another person with it looking like it came from person1.

Please don't provide an answer to this for the script kiddies trolling
usenet.

Oct 14 '07 #3

P: n/a
On 14/10/2007 22:08, Lars Eighner wrote:
Why, exactly, don't you do that in your mail server? It's the right tool
for this job.
There's more to what I'm planning to do than I included in my original
post. Rather than over complicate the original post, I've included only
the details that relate to my question regarding mail forwarding using php.

Regards,
Craig.
Oct 14 '07 #4

P: n/a
On 14/10/2007 22:56, ELINTPimp wrote:
If I'm reading this correctly, it looks like he wants to be able to
spoof the email forward to look like the original sender sent it. I
think that if this is a legitimate question, if you aren't looking to
be, you will soon find yourself a SPAM hub. Essentially, you could
take an email from person1, change the contents, and send it to
another person with it looking like it came from person1.

Please don't provide an answer to this for the script kiddies trolling
usenet.

j3sus_chr1st on a bike!

Rather than deliver mail directly to my inbox, I'm forwarding it to a
gmail account. gmail then kindly filters virus and spam. gmail then
forwards mail back the original email account, where it gets piped to my
php script.

The php script parses the email for a header which indicates that it's
been forwarded from a gmail account. If it finds that header which
gmail added, it delivers it to my inbox, otherwise, the mail gets
forwarded to gmail.

There are 2 reasons for doing this: 1) mail backup 2) extra antivirus
and antispam.

I didn't want to include these extra details because they're not really
relevant to my original question and would make it easier for people to
go off topic (how wrong I was!). Its great to see moral people out
there on the internet, but please don't jump the gun on a whim!!!

Now please, can we get back on topic: using php to forward email...

Regards,
Craig.
Oct 14 '07 #5

P: n/a
Craig Hurley wrote:
On 14/10/2007 22:56, ELINTPimp wrote:
>If I'm reading this correctly, it looks like he wants to be able to
spoof the email forward to look like the original sender sent it. I
think that if this is a legitimate question, if you aren't looking to
be, you will soon find yourself a SPAM hub. Essentially, you could
take an email from person1, change the contents, and send it to
another person with it looking like it came from person1.

Please don't provide an answer to this for the script kiddies trolling
usenet.


j3sus_chr1st on a bike!

Rather than deliver mail directly to my inbox, I'm forwarding it to a
gmail account. gmail then kindly filters virus and spam. gmail then
forwards mail back the original email account, where it gets piped to my
php script.

The php script parses the email for a header which indicates that it's
been forwarded from a gmail account. If it finds that header which
gmail added, it delivers it to my inbox, otherwise, the mail gets
forwarded to gmail.

There are 2 reasons for doing this: 1) mail backup 2) extra antivirus
and antispam.

I didn't want to include these extra details because they're not really
relevant to my original question and would make it easier for people to
go off topic (how wrong I was!). Its great to see moral people out
there on the internet, but please don't jump the gun on a whim!!!

Now please, can we get back on topic: using php to forward email...

Regards,
Craig.
Craig,

Lars is correct. You should do this in your mail server. You won't be
able to forward with PHP and keep the previous headers intact.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 14 '07 #6

P: n/a
In our last episode,
<Dj*******************@news.indigo.ie>,
the lovely and talented Craig Hurley
broadcast on comp.lang.php:
On 14/10/2007 22:08, Lars Eighner wrote:
>Why, exactly, don't you do that in your mail server? It's the right tool
for this job.
There's more to what I'm planning to do than I included in my original
post. Rather than over complicate the original post, I've included only
the details that relate to my question regarding mail forwarding using php.
If you are doing some more than you said, then you are up to no good.

An honest person would do this in his mail server.
--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 463 days to go.
What do you do when you're debranded?
Oct 14 '07 #7

P: n/a
On 14/10/2007 23:38, Lars Eighner wrote:
If you are doing some more than you said, then you are up to no good.

An honest person would do this in his mail server.

Lars, please see my reply to ELINPimp.. what I'm trying to do is not a
basic forwarding rule.

I'm on shared hosting and I'm trying to do something a bit more advanced
than the hosting providers control panel provides for. They do however
allow users to pipe email to a script.

Is this newsgroup for discussing how to forward mail on a dedicated or
shared mail server? No.

Is this newsgroup for discussing php (including mail())? Yes.

Kindly stay on topic.

Regards,
Craig.
Oct 15 '07 #8

P: n/a
In our last episode,
<5_*******************@news.indigo.ie>,
the lovely and talented Craig Hurley
broadcast on comp.lang.php:
On 14/10/2007 23:38, Lars Eighner wrote:
>If you are doing some more than you said, then you are up to no good.

An honest person would do this in his mail server.

Lars, please see my reply to ELINPimp.. what I'm trying to do is not a
basic forwarding rule.
I read it. What you admit to is wanting to make google do your filtering
for you. Obviously you this is not just your personal mail, because you
wouldn't need forged headers for that. No you are obviously reselling
services and do not want your users to realize you are sending their mail
through googles filters and ripping off processing time from google for your
own profit.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 463 days to go.
What do you do when you're debranded?
Oct 15 '07 #9

P: n/a
On 15/10/2007 11:32, Lars Eighner wrote:
I read it. What you admit to is wanting to make google do your filtering
for you. Obviously you this is not just your personal mail, because you
wouldn't need forged headers for that. No you are obviously reselling
services and do not want your users to realize you are sending their mail
through googles filters and ripping off processing time from google for your
own profit.
Lars, you're funny. Do try to get a hold on your imagination. When
you're finished trying to get that imagination under control, have a
look at these:
http://www.google.ie/search?hl=en&q=...ter+spam&meta=

The very first link (from mboffin.com) is the most informative. It's
the process in that blog that I'm trying to replicate using a php
script. Unfortunately that particular bloggers site is down at the
moment, but it's a popular site so I'm sure it won't be long before it's
back up.

Finally, try to stay on topic please: using php mail to forward email?
I realise you may find this hard, what with your over-active imagination.

Have a nice day,
Craig.
Oct 15 '07 #10

P: n/a
On Oct 15, 3:46 am, Craig Hurley <s...@thehurley.comwrote:
On 15/10/2007 11:32, Lars Eighner wrote:
I read it. What you admit to is wanting to make google do your filtering
for you. Obviously you this is not just your personal mail, because you
wouldn't need forged headers for that. No you are obviously reselling
services and do not want your users to realize you are sending their mail
through googles filters and ripping off processing time from google for your
own profit.

Lars, you're funny. Do try to get a hold on your imagination. When
you're finished trying to get that imagination under control, have a
look at these:http://www.google.ie/search?hl=en&q=...ter+spam&meta=

The very first link (from mboffin.com) is the most informative. It's
the process in that blog that I'm trying to replicate using a php
script. Unfortunately that particular bloggers site is down at the
moment, but it's a popular site so I'm sure it won't be long before it's
back up.

Finally, try to stay on topic please: using php mail to forward email?
I realise you may find this hard, what with your over-active imagination.

Have a nice day,
Craig.
Hi Craig,

Have you made any progress on this? I'm interested in the same thing
-- and Lars is correct: it's totally for global domination purposes.

Actually, I'm also on a shared server and I want to be able to
simulate CPanel forwarders on-the-fly without having to login to
CPanel and setup each one of them. Not that it's at all important
what I want to do. I really wish that people could just focus on the
the specific question instead of giving advice and insinuation.

Thanks,
Dustin

Oct 23 '07 #11

P: n/a
In our last episode, <11**********************@q5g2000prf.googlegroups. com>,
the lovely and talented co*****@dustinbuss.com broadcast on comp.lang.php:
On Oct 15, 3:46 am, Craig Hurley <s...@thehurley.comwrote:
>On 15/10/2007 11:32, Lars Eighner wrote:
I read it. What you admit to is wanting to make google do your filtering
for you. Obviously you this is not just your personal mail, because you
wouldn't need forged headers for that. No you are obviously reselling
services and do not want your users to realize you are sending their mail
through googles filters and ripping off processing time from google for your
own profit.

Lars, you're funny. Do try to get a hold on your imagination. When
you're finished trying to get that imagination under control, have a
look at these:http://www.google.ie/search?hl=en&q=...ter+spam&meta=

The very first link (from mboffin.com) is the most informative. It's
the process in that blog that I'm trying to replicate using a php
script. Unfortunately that particular bloggers site is down at the
moment, but it's a popular site so I'm sure it won't be long before it's
back up.

Finally, try to stay on topic please: using php mail to forward email?
I realise you may find this hard, what with your over-active imagination.

Have a nice day,
Craig.
Hi Craig,
Have you made any progress on this? I'm interested in the same thing
-- and Lars is correct: it's totally for global domination purposes.
Actually, I'm also on a shared server and I want to be able to
simulate CPanel forwarders on-the-fly without having to login to
CPanel and setup each one of them. Not that it's at all important
what I want to do. I really wish that people could just focus on the
the specific question instead of giving advice and insinuation.
There is an honest way to do. The requirement on the problem that the
headers be forged makes insinuation unnecessary. People with honest
intentions do not need to forge headers.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 455 days to go.
What do you do when you're debranded?
Oct 23 '07 #12

P: n/a
Hey folks, interest reading here. Let me spice up the subject with my
question. I'm trying to link promoters in my area through my
website. So this is what I'm trying to do: User sends an email to
the promoter by clicking on the link on my website or a web form. The
the email comes to me, subject "promoter2" which will tell the email
to forward the email to promoter2 email address. Now, I want to
prevent the promoter to see the email address of the person that sends
it so they don't add them to their list and spam them later on. So
basically, the email to the promoter would come from my email address
with the question from the user. How about it?

Oct 23 '07 #13

P: n/a
ar*****@gmail.com wrote:
Hey folks, interest reading here. Let me spice up the subject with my
question. I'm trying to link promoters in my area through my
website. So this is what I'm trying to do: User sends an email to
the promoter by clicking on the link on my website or a web form. The
the email comes to me, subject "promoter2" which will tell the email
to forward the email to promoter2 email address. Now, I want to
prevent the promoter to see the email address of the person that sends
it so they don't add them to their list and spam them later on. So
basically, the email to the promoter would come from my email address
with the question from the user. How about it?

Your website is sending the mail. Just set the headers accordingly.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 24 '07 #14

P: n/a
ar*****@gmail.com wrote:
Hey folks, interest reading here. Let me spice up the subject with my
question. I'm trying to link promoters in my area through my
website. So this is what I'm trying to do: User sends an email to
the promoter by clicking on the link on my website or a web form. The
the email comes to me, subject "promoter2" which will tell the email
to forward the email to promoter2 email address. Now, I want to
prevent the promoter to see the email address of the person that sends
it so they don't add them to their list and spam them later on. So
basically, the email to the promoter would come from my email address
with the question from the user. How about it?

I should add - if you're not using a mailto: link - but rather using PHP
to actually send the email.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 24 '07 #15

P: n/a
co*****@dustinbuss.com wrote:
Hi Craig,

Have you made any progress on this? I'm interested in the same thing
-- and Lars is correct: it's totally for global domination purposes.

Actually, I'm also on a shared server and I want to be able to
simulate CPanel forwarders on-the-fly without having to login to
CPanel and setup each one of them. Not that it's at all important
what I want to do. I really wish that people could just focus on the
the specific question instead of giving advice and insinuation.

Thanks,
Dustin
Hi Dustin,
If your hosted on a server that runs exim and CPanel, there's an easy
way to implement this... have a read of this:
http://www.webpronews.com/blogtalk/2...lter-on-cpanel
I'm hosted on a server that runs exim and DirectAdmin, so the .forward
file doesn't work in the way outlined on that site--I'm limited to using
a .forward file for the real hosting package user (the account I use to
log into DA and SSH), any other email account is considered a virtual
user account, and the .forward file doesn't fire for those accounts.
http://www.directadmin.com/forum/arc...hp/t-4390.html

The above scenario means I would have to give out my real users email
address, and I don't want that. I want to be able to give out random
virtual email addresses, then when mail comes in, forward it onto gmail
(and its great spam filter) and gmail then forwards it back to another
of my virtual email accounts.
I have implemented it using a number of different forwarders to gmail
and back to my real user account. It's not quite the way I wanted it
(going to the real user account) but it works. I haven't had time to
dig deeper into emulating the .forward files by piping incoming email to
a php script; I hope to have a proper look before the year end.
Good luck.
Craig.
Oct 30 '07 #16

This discussion thread is closed

Replies have been disabled for this discussion.