|
Posted by Lee C. Haas on 11/18/05 07:04
Hi from a newbie trying to teach himself to use PHP,
I have a formail php handler from http://www.thesitewizard.com working
on my site.
But, I would like to provide my visitors with checkbox options for
deciding where to send the message. Multiple checks to be allowed.
I have created the code to generate the string to place in the first
argument of the mail() function. I will paste it below.
Unfortunately, no matter what I try, the message only goes to the
first address in the comma delimited string.
I have placed an echo statement in the php code to look at the $mailto
variable and observed all the addresses and I can see the multiple
addresses in the "To:" field of the received messages.
I would hate to resort to multiple mail() calls for each address, but
I am at my wits end with testing. Most likely it is something stupid.
Any help would be appreciated.
Lee
code follows: ------------------------------
On the shtml page is the following:
....
<form action="fbx.php" method="post"><BR>
....
<INPUT type="checkbox" checked name="recipients[]"
value="mailto_0"> Business office (default if none checked)<BR>
<INPUT type="checkbox" name="recipients[]"
value="mailto_1"> Web editor<br>
<INPUT type="checkbox" name="recipients[]"
value="mailto_2"> Club Manager
....
<input type="submit" value="Send Feedback" />
....
--------------end of shtml page quoting ------------
------- in the fbx.php file: ----------------------
....
$mailto_0= 'addr0@domain.nul' ; //use this if no checks at all
$mailto_1= 'addr1@domain.nul' ;
$mailto_2= 'addr2@domain.nul' ;
....
// more option vars are also set here
// code for email, from name, and comments are also here
.... following is my code for dealing with multiple addresses
$number_of_recipients = count($recipients) ;
if ($number_of_recipients==0) {
$mailto=$mailto_0 ; // set recipient to default value ( $mailto_0
)
}
elseif($number_of_recipients >= 1) {
foreach($recipients as $index => $address) {
if ($index ==0) {$mailto = $$address ; }
else {$mailto = $mailto.", ".$$address ; }
}
}
else {unset($mailto) ; //avoid untested cases, later code aborts
}
if (isset($mailto)){$mailto .= "\r\n" ; } //(also tried without this)
.... after more code the mail function is called (all on one line)
mail($mailto, $subject, $messageproper, "From: \"$name\"
<$email>\r\nReply-To: \"$name\" <$email>\r\nX-Mailer: chfeedback.php
2.04" );
header( "Location: $thankyouurl" );
exit ;
---------------------- end of fbx.php file ---------------------
This is pasted from one of the test messages: (I x'ed the domains)
To: a0@incxxx.net, lee@thexxx.org, c2@conxxx.org
but the message only arrived at incxxx.net
Again, any help appreciated.
Lee Haas, Raleigh, NC
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Email may be sent to me by using:
http://tinyurl.com/fylz
[Back to original message]
|