Hello! I'm new to PHP AND to this forum. Just trying to learn PHP at the moment - so, I've written the below script and I've been testing it. Seems to work okay (it's invoked from a standard HTML page that is used to pass ONE field in the invoking URL - and that field is to indicate "which band member" is to get the email), but there is an odd issue with it.
In the logic paragraph below that begins with "if (isset($_REQUEST['email']))"
there is something very odd and interesting happening with a field... and I thought you all would be the right people to ask about it.
Now, I realize that this is "server side" stuff...but I still don't understand how the following could be happening... but it is...
So, here is my issue:
You can see how field "recipient" is set immediately upon entering the code... and you can also see how I then make a copy of that value into field $recip. The reason I'm making this copy of the field is so I can "restore" it back into field $recipient after $recipient is clobbered.
I suppose it must be this line that is clobbering $recipient:
mail($senditto, "Subject: $subject$phnlit$phn",
$message, "From: $email" );
Reason I say that: The email that results from this command ALWAYS goes first to jason@domain2.com (the email also always goes (as it should) to bertha@domain3.com)... but the first of the two email addresses that is sent to is ALWAYS jason's email address even when I vary the recipient from invoking page.
I'm baffled. Thought it might make a puzzle for someone here - plus really want to learn what I've done wrong... So, anybody know why $recipient is getting clobbered?
Thank you in advance (and sorry about the long post).
swoop
<html>
<body>
<?php
$recipient = ($_GET['EmailToList']) ;
$recip = $recipient ;
$ecolr = "blue" ;
$phcolr = "blue" ;
$colr = "blue" ;
$emsg = ("Dear ".$recipient) ;
$smsg = "" ;
$seml = "" ;
$ssub = "" ;
$sphn = "" ;
$eastr = "*" ;
$phastr = "" ;
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}
$smsg = $REQUEST['message'] ;
$seml = $REQUEST['email'] ;
$ssub = $REQUEST['subject'] ;
$sphn = $REQUEST['phn'] ;
$usephn = "" ;
$len = strlen($sphn);
if ($len > 0)
{
$myarray = str_split($sphn) ;
foreach ($myarray as $value)
{
if (($value < '0') || ($value > '9')) $usephn = $usephn ;
else $usephn = $usephn.$value ;
}
$lenu = strlen($usephn);
if ($lenu != 10)
{
$phcolr = "red" ;
$colr = "red" ;
$phastr = "*" ;
$emsg = ($recipient." will need a 10-char phn num (incl area code)") ;
}
}
$sphn = $usephn;
if (isset($REQUEST['email']))
{//if "email" is filled out, proceed //check if the email address is invalid
$mailcheck = spamcheck($REQUEST['email']);
if ($mailcheck==FALSE)
{
$ecolr = "red" ;
$colr = "red" ;
$emsg = ($recipient." will need a valid email address to contact you") ;
}
else
{
if ($colr != "red")
{//send email
$email = $REQUEST['email'] ;
$subject = $REQUEST['subject'] ;
$phn = $REQUEST['phn'] ;
$phnlit = " phn:" ;
$message = ($REQUEST['message'].$phnlit.$phn) ;
$senditto = "fritter@domain1.net" ;
$recipient = $recip ;
if ($recipient = "Jason")
{
$senditto = "jason@domain2.com" ;
}
$recipient = $recip ;
$senditto = ($senditto.", bertha@domain3.com");
mail($senditto, "Subject: $subject$phnlit$phn",
$message, "From: $email" );
$recipient = $recip ; // somehow senditto stuff forces reset here
$emsg = "MAIL SENT!" ;
$colr = "green" ;
}
}
}
echo "<form method='post' action='emailtester.php?EmailToList=$recipient')>
<br />
<font size='4' color='$colr'>
$emsg</font><br />
<br />
Sender's Email: <input name='email' type='text' value=$seml ><font size='5' color='$ecolr'>$eastr</font><br />
Sender's Phone#: <input name='phn' type='text' value=$sphn ><font size='5' color='$phcolr'>$phastr</font><br />
Subject: <input name='subject' type='text' value=$ssub ><br />
Message:<br />
<textarea name='message' rows='3' cols='40'>$smsg
</textarea><br />
<input type='submit' value='SUBMIT' />
</form>
<form name='form1'>
<input onclick='window.close();' type='button' name='CloseButton' value='CLOSE'>
</form>";
?></body>
</html>