This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Dreamweaver > February 2004 > php email query





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author php email query
Blair Rasmussen

2004-02-28, 4:28 pm

Have a simple contact form. A select list has 5 names - this is used to
determine who the email goes to. How can I write a PHP if statement on the
process page to say if the value passed from the select list was "bob", send
the email to bob@domain.com. If form returned "Susy", send to usy@domain
..com...

--
--
Regards,

Blair Rasmussen
Oshima Web Solutions
------------------------------
http://www.oshima.ca
http://www.albertarowing.ca
------------------------------



Ken Ford - PVII Support

2004-02-28, 5:28 pm

Blair,

Assuming the name of the select is selectTo and the comments field is named Comments you could do this:

<?php
$comments = $_POST['Comments'];
$mailTo = $_POST['selectTo'];
switch ($mailTo) {
case "bob":
$emailTo = "bob@domain.com";
break;
case "suzy":
$emailTo = "suzy@domain.com";
break;
case "mike":
$emailTo = "mike@domain.com";
break;
case "bill":
$emailTo = "bill@domain.com";
break;
case "karen":
$emailTo = "karen@domain.com";
break;
}
mail($mailTo, "Feedback Form", $comments, "From: webmaster@domain.com");
?>


--
Ken Ford
Certified Dreamweaver MX 2004 Developer
PVII Support Team
http://www.projectseven.com


"Blair Rasmussen" <brasmussen_ca@yahoo.com> wrote in message news:c1qqeq$598$1@forums.macromedia.com...
> Have a simple contact form. A select list has 5 names - this is used to
> determine who the email goes to. How can I write a PHP if statement on the
> process page to say if the value passed from the select list was "bob", send
> the email to bob@domain.com. If form returned "Susy", send to usy@domain
> .com...
>
> --
> --
> Regards,
>
> Blair Rasmussen
> Oshima Web Solutions
> ------------------------------
> http://www.oshima.ca
> http://www.albertarowing.ca
> ------------------------------
>
>
>



Alexandru COSTIN

2004-02-28, 6:28 pm

Hi,
Or better
<?php
$comments = $_POST['Comments'];
$mailTo = $_POST['selectTo'];
$emailTo = $mailTo."@domain.com";
mail($emailTo, "Feedback Form", $comments, "From: webmaster@domain.com");

?>

Ken's code was using $mailTo instead of $emailTo in the mail() function
parameters

Alexandru

Ken Ford - PVII Support wrote:
> Blair,
>
> Assuming the name of the select is selectTo and the comments field is named Comments you could do this:
>
> <?php
> $comments = $_POST['Comments'];
> $mailTo = $_POST['selectTo'];
> switch ($mailTo) {
> case "bob":
> $emailTo = "bob@domain.com";
> break;
> case "suzy":
> $emailTo = "suzy@domain.com";
> break;
> case "mike":
> $emailTo = "mike@domain.com";
> break;
> case "bill":
> $emailTo = "bill@domain.com";
> break;
> case "karen":
> $emailTo = "karen@domain.com";
> break;
> }
> mail($mailTo, "Feedback Form", $comments, "From: webmaster@domain.com");
> ?>
>
>


--
Alexandru COSTIN
Chief Operating Officer
http://www.interakt.ro/
+4021 312 5312
Ken Ford - PVII Support

2004-02-28, 6:28 pm

Oops - thank you Alexandru

Mine should have said:

mail($emailTo, "Feedback Form", $comments, "From: webmaster@domain.com");

--
Ken Ford
Certified Dreamweaver MX 2004 Developer
PVII Support Team
http://www.projectseven.com


"Alexandru COSTIN" <acostin@REMOVEinterakt.ro> wrote in message news:c1r1gr$bst$1@forums.macromedia.com...
> Hi,
> Or better
> <?php
> $comments = $_POST['Comments'];
> $mailTo = $_POST['selectTo'];
> $emailTo = $mailTo."@domain.com";
> mail($emailTo, "Feedback Form", $comments, "From: webmaster@domain.com");
>
> ?>
>
> Ken's code was using $mailTo instead of $emailTo in the mail() function
> parameters
>
> Alexandru
>
> Ken Ford - PVII Support wrote:
>
> --
> Alexandru COSTIN
> Chief Operating Officer
> http://www.interakt.ro/
> +4021 312 5312



Alexandru COSTIN

2004-02-28, 6:28 pm

You are welcome :)
I am reviewing code in InterAKT now as I have "almost" quit programming
for other areas, so I have good eyes for this kind of mistakes.

As for my optimized version - this is an old personal problem I have - I
optimize every code I get, even if this is not completely necessary - as
Knuth said, "premature optimization is the root of all evil".

Your code is more flexible in terms of e-mail address independence from
a single domain - and also more clear for a begginer.

Alexandru

Ken Ford - PVII Support wrote:

> Oops - thank you Alexandru
>
> Mine should have said:
>
> mail($emailTo, "Feedback Form", $comments, "From: webmaster@domain.com");
>


--
Alexandru COSTIN
Chief Operating Officer
http://www.interakt.ro/
+4021 312 5312
Alexandru COSTIN

2004-02-28, 6:28 pm

Hey,
Check the messages above in the thread

Alexandru

Blair Rasmussen wrote:

> Hi Ken, thanks - this is what I have - no error, but no email delivered
> either. Can you spot anything:
>
> <?php
> $message = $_POST['tfmessage'] ;
> $name = $_POST['tfname'] ;
> $subject = $_POST['tfsubject'] ;
> $mailTo = $_POST['slrecipient'];
> switch ($mailTo) {
> case "brasmussen":
> $emailTo = "rasmussen@oshima.ca";
> break;
> case "ercgeneral":
> $emailTo = aaa@telusplanet.net";
> break;
> case "cphillips":
> $emailTo = bbb@gov.ab.ca";
> break;
> case "msteacy":
> $emailTo = ccc@edm.clarkbuilders.com";
> break;
> }
> mail($mailTo, "Feedback from ERC Website", $message, $tfemail);
> ?>
>


--
Alexandru COSTIN
Chief Operating Officer
http://www.interakt.ro/
+4021 312 5312
Ken Ford - PVII Support

2004-02-28, 6:28 pm

Yeah an oops on my part, this should work:

mail($emailTo, "Feedback from ERC Website", $message, $tfemail);

--
Ken Ford
Certified Dreamweaver MX 2004 Developer
PVII Support Team
http://www.projectseven.com


"Blair Rasmussen" <brasmussen_ca@yahoo.com> wrote in message news:c1r2sj$d5j$1@forums.macromedia.com...
> Hi Ken, thanks - this is what I have - no error, but no email delivered
> either. Can you spot anything:
>
> <?php
> $message = $_POST['tfmessage'] ;
> $name = $_POST['tfname'] ;
> $subject = $_POST['tfsubject'] ;
> $mailTo = $_POST['slrecipient'];
> switch ($mailTo) {
> case "brasmussen":
> $emailTo = "rasmussen@oshima.ca";
> break;
> case "ercgeneral":
> $emailTo = aaa@telusplanet.net";
> break;
> case "cphillips":
> $emailTo = bbb@gov.ab.ca";
> break;
> case "msteacy":
> $emailTo = ccc@edm.clarkbuilders.com";
> break;
> }
> mail($mailTo, "Feedback from ERC Website", $message, $tfemail);
> ?>
>
> --
> --
> Regards,
>
> Blair Rasmussen
> Oshima Web Solutions
> ------------------------------
> http://www.oshima.ca
> http://www.albertarowing.ca
> ------------------------------
>
>
> "Ken Ford - PVII Support" <kford@projectseven.com> wrote in message
> news:c1qub5$8rj$1@forums.macromedia.com...
> named Comments you could do this:
> news:c1qqeq$598$1@forums.macromedia.com...
> the
> send
>
>



Blair Rasmussen

2004-02-28, 6:28 pm

Hi Ken, thanks - this is what I have - no error, but no email delivered
either. Can you spot anything:

<?php
$message = $_POST['tfmessage'] ;
$name = $_POST['tfname'] ;
$subject = $_POST['tfsubject'] ;
$mailTo = $_POST['slrecipient'];
switch ($mailTo) {
case "brasmussen":
$emailTo = "rasmussen@oshima.ca";
break;
case "ercgeneral":
$emailTo = aaa@telusplanet.net";
break;
case "cphillips":
$emailTo = bbb@gov.ab.ca";
break;
case "msteacy":
$emailTo = ccc@edm.clarkbuilders.com";
break;
}
mail($mailTo, "Feedback from ERC Website", $message, $tfemail);
?>

--
--
Regards,

Blair Rasmussen
Oshima Web Solutions
------------------------------
http://www.oshima.ca
http://www.albertarowing.ca
------------------------------


"Ken Ford - PVII Support" <kford@projectseven.com> wrote in message
news:c1qub5$8rj$1@forums.macromedia.com...
> Blair,
>
> Assuming the name of the select is selectTo and the comments field is

named Comments you could do this:
>
> <?php
> $comments = $_POST['Comments'];
> $mailTo = $_POST['selectTo'];
> switch ($mailTo) {
> case "bob":
> $emailTo = "bob@domain.com";
> break;
> case "suzy":
> $emailTo = "suzy@domain.com";
> break;
> case "mike":
> $emailTo = "mike@domain.com";
> break;
> case "bill":
> $emailTo = "bill@domain.com";
> break;
> case "karen":
> $emailTo = "karen@domain.com";
> break;
> }
> mail($mailTo, "Feedback Form", $comments, "From: webmaster@domain.com");
> ?>
>
>
> --
> Ken Ford
> Certified Dreamweaver MX 2004 Developer
> PVII Support Team
> http://www.projectseven.com
>
>
> "Blair Rasmussen" <brasmussen_ca@yahoo.com> wrote in message

news:c1qqeq$598$1@forums.macromedia.com...
the[color=darkred]
send[color=darkred]
>
>



Blair Rasmussen

2004-02-28, 6:29 pm

Got it - thanks Ken and Alexandru!

--
--
Regards,

Blair Rasmussen
Oshima Web Solutions
------------------------------
http://www.oshima.ca
http://www.albertarowing.ca
------------------------------


"Ken Ford - PVII Support" <kford@projectseven.com> wrote in message
news:c1r337$dcf$1@forums.macromedia.com...
> Yeah an oops on my part, this should work:
>
> mail($emailTo, "Feedback from ERC Website", $message, $tfemail);
>
> --
> Ken Ford
> Certified Dreamweaver MX 2004 Developer
> PVII Support Team
> http://www.projectseven.com
>
>
> "Blair Rasmussen" <brasmussen_ca@yahoo.com> wrote in message

news:c1r2sj$d5j$1@forums.macromedia.com...
webmaster@domain.com");[color=darkred]
to[color=darkred]
on[color=darkred]
"bob",[color=darkred]
usy@domain[color=darkred]
>
>



Michael Fesser

2004-02-28, 6:29 pm

.oO(Alexandru COSTIN)

>$comments = $_POST['Comments'];
>$mailTo = $_POST['selectTo'];
>$emailTo = $mailTo."@domain.com";
>mail($emailTo, "Feedback Form", $comments, "From: webmaster@domain.com");


Bad solution.

With this the user is able to send tons of emails to _any_ address on
that domain, there's no validation of the input!

I would prefer the switch-statement or something similar as a kind of a
whitelist: Everything is blocked except for some specific addresses.

Micha
Michael Fesser

2004-02-28, 6:29 pm

.oO(Alexandru COSTIN)

>$comments = $_POST['Comments'];
>$mailTo = $_POST['selectTo'];
>$emailTo = $mailTo."@domain.com";
>mail($emailTo, "Feedback Form", $comments, "From: webmaster@domain.com");


Bad solution.

With this the user is able to send tons of emails to _any_ address on
that domain, there's no validation of the input!

I would prefer the switch-statement or something similar as a kind of a
whitelist: Everything is blocked except for some specific addresses.

Micha
Gary White

2004-02-28, 8:28 pm

"Michael Fesser" <netizen@gmx.net> wrote in message
news:ak4240hnak5bcj47riql36knvqp7775b6v@4ax.com...
> .oO(Alexandru COSTIN)
>
>
> Bad solution.
>
> With this the user is able to send tons of emails to _any_ address on
> that domain, there's no validation of the input!
>
> I would prefer the switch-statement or something similar as a kind of a
> whitelist: Everything is blocked except for some specific addresses.



You must feel very strongly about this, Micha. You posted it twice. ;-)

I agree that a finite list is a better idea. If the list is small, a switch
construct would be fine. If the list were larger, it might be easier to have
the names and e-mail addresses in an array:

$emails['bob']="bob@domain.com";
$emails['carol']="carol@domain.com";
$emails['ted']="ted@domain.com";
$emails['alice']="alice@domain.com";

Then you just do the lookup:

$selectTo=$_POST['selectTo'];
if (array_key_exists($selectTo))
$emailTo=$emails[$selectTo];
else
die("E-mail address not found");

The other thing that would allow, would be that you could also easily direct
e-mails to addresses at different domains if you later needed to.

Gary


Michael Fesser

2004-02-28, 8:28 pm

.oO(Gary White)

>You must feel very strongly about this, Micha. You posted it twice. ;-)


I had cancelled the first one, thought I'd have to add something (but
removed it before re-posting).

Seems like you were faster (or your server doesn't accept cancels). :)

Micha
Ian Firth

2004-02-29, 5:28 am

In article <c1r3ai$dkr$1@forums.macromedia.com>, brasmussen_ca@yahoo.com
says...

> Got it - thanks Ken and Alexandru!


Blair, do you have mysql available on that server ?

I've switched to storing email addresses in a table, then populating
dropdowns with it. When the form is submitted, the address is looked up
based on an ID, and the address is filled in.

This keeps the address out of the HTML so it can't be picked up by
spambots.

--
Regards,
Ian Firth
Gary White

2004-02-29, 8:28 am

On Sun, 29 Feb 2004 01:02:46 +0100, Michael Fesser <netizen@gmx.net>
wrote:

> .oO(Gary White)
>
>
>I had cancelled the first one, thought I'd have to add something (but
>removed it before re-posting).
>
>Seems like you were faster (or your server doesn't accept cancels). :)



<chuckle /> I was told once that the MM server does not accept cancels.
You did see the wink, right. I was just messing with you. :-)


Gary
Blair Rasmussen

2004-02-29, 1:28 pm

Yes, mysql is available - but I've had fits getting it to do anything on my
machine let alone the server!

--
--
Regards,

Blair Rasmussen
Oshima Web Solutions
------------------------------
http://www.oshima.ca
http://www.albertarowing.ca
------------------------------


"Ian Firth" <if@divsoft.com> wrote in message
news:MPG.1aab5b3d25207b7d98983a@forums.macromedia.com...
> In article <c1r3ai$dkr$1@forums.macromedia.com>, brasmussen_ca@yahoo.com
> says...
>
>
> Blair, do you have mysql available on that server ?
>
> I've switched to storing email addresses in a table, then populating
> dropdowns with it. When the form is submitted, the address is looked up
> based on an ID, and the address is filled in.
>
> This keeps the address out of the HTML so it can't be picked up by
> spambots.
>
> --
> Regards,
> Ian Firth



Michael Fesser

2004-02-29, 1:28 pm

.oO(Gary White)

><chuckle /> I was told once that the MM server does not accept cancels.


I don't really care. ;)

Micha
Gary White

2004-02-29, 2:28 pm

"Michael Fesser" <netizen@gmx.net> wrote in message
news:ms74409m8smnfhf2bekncf7skte4utu580@4ax.com...
> .oO(Gary White)
>
>
> I don't really care. ;)



Me either, but knowing that saves wasting a couple of mouse clicks trying.
:-)

Gary


Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews