Forum Moderators: coopster

Message Too Old, No Replies

another mail issue

         

Gilead

5:39 pm on Nov 15, 2011 (gmt 0)

10+ Year Member



In this part, the member has logged in, but they want to change something more than just their login name and password.
For that, they fill out this form, which gets mailed to the admin to make the big changes. The values are passed via hidden fields. Everything seems to be fine, except it won't mail. Also the checked boxes used come through, now for some reason they don't.

changeuser.php
there is another form above this to change regular user info- that works just fine.
...
<h2> Do you need to update other information? </h2>

<form method="POST" name="changebig" action="change.php">
<h3>What do you need to change?</h3>
<input type="checkbox" name="changeitem[]" value="accountnumber"><b>account number</b><br />
<input type="checkbox" name="changeitem[]" value="contactid"><b>contact id</b><br />
<input type="checkbox" name="changeitem[]" value="orgname"><b>organization name</b><br />
<input type="checkbox" name="changeitem[]" value="accountname"><b>account name</b><br />
<input type="checkbox" name="changeitem[]" value="networkrep"><b>network representative</b><br />
<input type="checkbox" name="changeitem[]" value="network"><b>network</b><br />

<textarea name="whychange" rows="5" cols="25">Please explain what has occurred that necessitates these changes.</textarea><br />
<input type="hidden" name="email" value="<?php echo $email; ?>">
<input type="hidden" name="contactid" value="<?php echo $contactid; ?>">
<input type="hidden" name="account_number" value="<?php echo $account_number; ?>">
<input type="hidden" name="organizational_title" value="<?php echo $organization_title; ?>">
<input type="hidden" name="account_name" value="<?php echo $account_name; ?>">
<input type="hidden" name="organizationDBA" value="<?php echo $organizationDBA; ?>">
<input type="hidden" name="network_representative" value="<?php echo $network_representative; ?>">
<input type="hidden" name="network" value="<?php echo $network; ?>">
<input type="hidden" name="firstname" value="<?php echo $firstname; ?>">
<input type="hidden" name="lastname" value="<?php echo $lastname; ?>">
<input type="submit" name="submit" value="submit"><input type="reset">
</form>

change.php
<?php
$to='testing@mytestemail.com';
$changeitem=$_POST['changeitem'];
$whychange=$_POST['whychange'];
$email=$_POST['email'];
$contactid=$_POST['contactid'];
$accountnumber=$_POST['account_number'];
$organization=$_POST['organization_title'];
$accountname=$_POST['account_name'];
$dba=$_POST['organizationDBA'];
$networkrep=$_POST['network_representative'];
$network=$_POST['network'];
$fname=$_POST['firstname'];
$lname=$_POST['lastname'];


$subject = "Member Change Form";
$headers = "From: '$email'\r\n";
$body = "This member needs to change:\n";
$body .= "'$changeitem' \n"; //when echo'ed this just says Array, used to show the actual selected items.
$body .= "Purpose for Change: '$whychange' \n";
$body .= "Contact Id: '$contactid' \n";
$body .= "Account Number: '$accountnumber' \n";
$body .= "Org Title: '$organization' \n";
$body .= "Account Name; '$accountname' \n";
$body .= "DBA: '$dba' \n";
$body .= "Rep: '$networkrep' \n";
$body .= "Network: '$network' \n";
$body .= "First Name: '$fname' \n";
$body .= "Last Name: '$lname' \n";
$body .= "Email: '$email' \n";

error_reporting(E_ALL);
echo $to;
echo '<br />';
echo $subject;
echo '<br />';
echo $headers;
echo '<br />';
echo $body;
//values come through here just fine, except the changeitem
if(mail($to,$subject,$body,$headers))
{
echo "Request made. We will contact you within 24 business hours.";
//makes me think it'll work, but no email is received.
}
else
{
echo "Message Not Sent";
}
?>

Thanks for the help!

penders

7:07 pm on Nov 15, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



error_reporting(E_ALL);


This should really go at the very start of your script to throw up all errors.

$body .= "'$changeitem' \n"; //when echo'ed this just says Array, used to show the actual selected items.


Because $changeitem is an Array. As specified in the HTML with trailing square brackets ...
name="changeitem[]"


In order to get all the values of the checkboxes you need to step through this array. To do this quickly for the sake of your email you could simply implode() [uk.php.net] it into a string (to get a comma separate list):

$body .= implode(', ',$changeitem)."\n";


//makes me think it'll work, but no email is received.


The mail() function returns true if it was accepted for delivery, but this doesn't necessarily mean it was sent/received successfully.

The problem might be the single quotes around the email address in the From: header...

$headers = "From: '$email'\r\n";


The single quotes should be omitted:
$headers = "From: $email\r\n";

Gilead

7:23 pm on Nov 15, 2011 (gmt 0)

10+ Year Member



Hmm, I thought you had to escape any variables that were in variables or am I just thinking of echo commands?

penders

11:09 pm on Nov 15, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not sure what you mean? You would only escape (ie. backslash escape) a variable in a double quoted string if you wanted that variable to appear as a literal in that string.

The single quotes in the double quoted string are just that; single quotes.

$headers = "From: '$email'\r\n";


If $email had the value "test@example.com" then $headers would become:
From: 'test@example.com'

(Which is not correct)

Gilead

4:20 pm on Nov 16, 2011 (gmt 0)

10+ Year Member



That did the trick!
Thanks so much!

Gilead

4:40 pm on Nov 16, 2011 (gmt 0)

10+ Year Member



Excellent! That got the ball rolling. Thanks for the fresh eyes.