Switch
am 20.11.2007 01:47:22 von Bill H
I wrote a PHP script that the user decides who they want to send the email
to based on the selection from a "dropdown" box. The essential part of the
script that I'm having problems with is:
/* Pre-defined script variables. */
$eol = "\n";
$mailto = 'me@mycorp.net';
$mailfrom = 'webserver@mycorp.net';
$subject = 'Contact Us Request';
/* Initialize a clean array to replace $_POST with clean data */
$etype = $_POST['etype'];
$errmsg = 'etype-: '.$etype.' | Case value-: ';
/* Define the mailto address
switch ($etype) {
case 0:
$mailto = 'sales@mycorp.net';
$errmsg .= '0';
break;
case 1:
$mailto = 'support@mycorp.net';
$errmsg .= '1';
break;
case 2:
$mailto = 'webmaster@mycorp.net';
$errmsg .= '2';
break;
case 3:
$mailto = 'myacct@mycorp.net';
$errmsg .= '3';
break;
default:
$mailto = 'me@mycorp.net';
$errmsg .= 'default';
}
..
..
builds an email and sends it to myself.
?>
The email shows up at the "me" address instead of the "myacct" address. The
problem is the email shows "etype-: 3 | Case value-: ". This indicates
that the switch didn't work at all. Can anyone tell me why?
Thanks,
Bill
Re: Switch
am 20.11.2007 02:20:31 von Csaba2000
Bill H wrote:
> /* Initialize a clean array to replace $_POST with clean data */
> $etype = $_POST['etype'];
> $errmsg = 'etype-: '.$etype.' | Case value-: ';
>
> /* Define the mailto address
> switch ($etype) {
> case 0:
> $mailto = 'sales@mycorp.net';
> $errmsg .= '0';
> break;
> case 1:
> $mailto = 'support@mycorp.net';
> $errmsg .= '1';
> break;
> case 2:
> $mailto = 'webmaster@mycorp.net';
> $errmsg .= '2';
> break;
> case 3:
> $mailto = 'myacct@mycorp.net';
> $errmsg .= '3';
> break;
> default:
> $mailto = 'me@mycorp.net';
> $errmsg .= 'default';
> }
> .
> .
> builds an email and sends it to myself.
> ?>
>
> The email shows up at the "me" address instead of the "myacct" address. The
> problem is the email shows "etype-: 3 | Case value-: ". This indicates
> that the switch didn't work at all. Can anyone tell me why?
>
Isn't it simpler to do:
$aMailTo = array('sales@mycorp.net', 'support@mycorp.net',
'webmaster@mycorp.net', 'myacct@mycorp.net');
$mailTo = 'me@mycorp.net'; // default
if (array_key_exists($etype, $aMailTo))
$mailTo = $aMailTo[$etype];
$errmsg .= "$etype";
By the way, in your code above, you haven't closed off
the comment that starts on the Define the mailto address line.
Also, though it shouldn't make a difference in the switch
statement, the type of $etype is string.
Csaba Gabor from Vienna
Re: Switch
am 20.11.2007 03:39:36 von Jerry Stuckle
Bill H wrote:
> I wrote a PHP script that the user decides who they want to send the email
> to based on the selection from a "dropdown" box. The essential part of the
> script that I'm having problems with is:
>
>
>
> /* Pre-defined script variables. */
> $eol = "\n";
> $mailto = 'me@mycorp.net';
> $mailfrom = 'webserver@mycorp.net';
> $subject = 'Contact Us Request';
>
> /* Initialize a clean array to replace $_POST with clean data */
> $etype = $_POST['etype'];
> $errmsg = 'etype-: '.$etype.' | Case value-: ';
>
> /* Define the mailto address
> switch ($etype) {
> case 0:
> $mailto = 'sales@mycorp.net';
> $errmsg .= '0';
> break;
> case 1:
> $mailto = 'support@mycorp.net';
> $errmsg .= '1';
> break;
> case 2:
> $mailto = 'webmaster@mycorp.net';
> $errmsg .= '2';
> break;
> case 3:
> $mailto = 'myacct@mycorp.net';
> $errmsg .= '3';
> break;
> default:
> $mailto = 'me@mycorp.net';
> $errmsg .= 'default';
> }
> .
> .
> builds an email and sends it to myself.
> ?>
>
> The email shows up at the "me" address instead of the "myacct" address. The
> problem is the email shows "etype-: 3 | Case value-: ". This indicates
> that the switch didn't work at all. Can anyone tell me why?
>
> Thanks,
>
> Bill
>
>
>
Bill,
Try
case '0':
case '1':
etc
Or, when I know it's a numeric value, I use:
$etype= isset($_POST['etype']) ? intval($_POST['etype']) ? 0;
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Switch
am 20.11.2007 04:01:29 von Bill H
Csaba:
How stupid could I get. The missing "close comment" was the problem.
I tried the array but it seems the:
if (array_key_exists($etype, $aMailTo)) {
$mailTo = $aMailTo[$etype];
$errmsg .= "$etype"; }
....didn't work but:
$mailTo = $aMailTo[$etype];
....did. Go figure.
Thanks very much.
Bill
"Csaba Gabor" wrote in message
news:c216a$47423353$506c17c2$5852@news.chello.at...
> Bill H wrote:
>> /* Initialize a clean array to replace $_POST with clean data */
>> $etype = $_POST['etype'];
>> $errmsg = 'etype-: '.$etype.' | Case value-: ';
>>
>> /* Define the mailto address
>> switch ($etype) {
>> case 0:
>> $mailto = 'sales@mycorp.net';
>> $errmsg .= '0';
>> break;
>> case 1:
>> $mailto = 'support@mycorp.net';
>> $errmsg .= '1';
>> break;
>> case 2:
>> $mailto = 'webmaster@mycorp.net';
>> $errmsg .= '2';
>> break;
>> case 3:
>> $mailto = 'myacct@mycorp.net';
>> $errmsg .= '3';
>> break;
>> default:
>> $mailto = 'me@mycorp.net';
>> $errmsg .= 'default';
>> }
>> .
>> .
>> builds an email and sends it to myself.
>> ?>
>>
>> The email shows up at the "me" address instead of the "myacct" address.
>> The problem is the email shows "etype-: 3 | Case value-: ". This
>> indicates that the switch didn't work at all. Can anyone tell me why?
>>
> Isn't it simpler to do:
> $aMailTo = array('sales@mycorp.net', 'support@mycorp.net',
> 'webmaster@mycorp.net', 'myacct@mycorp.net');
> $mailTo = 'me@mycorp.net'; // default
> if (array_key_exists($etype, $aMailTo))
> $mailTo = $aMailTo[$etype];
> $errmsg .= "$etype";
>
>
> By the way, in your code above, you haven't closed off
> the comment that starts on the Define the mailto address line.
> Also, though it shouldn't make a difference in the switch
> statement, the type of $etype is string.
>
> Csaba Gabor from Vienna
Re: Switch
am 20.11.2007 10:35:31 von Toby A Inkster
Bill H wrote:
> $mailto = 'me@mycorp.net';
For future reference, when using an example domain name, please use
example.(com|net|org). Mark Segal, who owns mycorp.net might not be
happy with you posting valid e-mail addresses at his domain to Usenet,
and potentially attracting spammers to it.
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 13 days, 16:31.]
USD/EUR Exchange Rate Graph
http://tobyinkster.co.uk/blog/2007/11/18/usd-eur/
Re: Switch
am 20.11.2007 23:51:28 von Bill H
Thanks Toby.
It neverceases to amaze the breadth of information all of us are unaware of.
:-)
Bill
"Toby A Inkster" wrote in message
news:3cma15-umb.ln1@ophelia.g5n.co.uk...
> Bill H wrote:
>
>> $mailto = 'me@mycorp.net';
>
> For future reference, when using an example domain name, please use
> example.(com|net|org). Mark Segal, who owns mycorp.net might not be
> happy with you posting valid e-mail addresses at his domain to Usenet,
> and potentially attracting spammers to it.
>
> --
> Toby A Inkster BSc (Hons) ARCS
> [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
> [OS: Linux 2.6.12-12mdksmp, up 13 days, 16:31.]
>
> USD/EUR Exchange Rate Graph
> http://tobyinkster.co.uk/blog/2007/11/18/usd-eur/