- This topic is empty.
-
AuthorPosts
-
August 18, 2010 at 10:15 am #29968
brianatlarge
MemberSo I’ve got the following form:
Then, the following PHP to process the form:
<?php
// Receiving variables
@$from = addslashes($_POST['from']);
@$to = addslashes($_POST['to']);
@$subject = addslashes($_POST['subject']);
@$message = addslashes($_POST['message']);
@$sendcopy = addslashes($_POST['sendcopy']);
//Sending Email to form owner
# Email to Owner
$headers = "From: $from";
if ($sendcopy == "on") {
mail($from, $subject, $message, $headers);
}
mail($to, $subject, $message, $headers);
header("Location: thanks.php");
?>It sends the form to the "to" address, but when I have the checkbox checked, it doesn’t send a copy of the email to the "from" address. This is so simple… why isn’t it working?
August 18, 2010 at 3:33 pm #81745thisishard
MemberHi, I haven’t used check boxes before so i might be wrong but check boxes pass their data to php in an array. So where you declare your variable to the post data it actually turns into an array with only one value (if the box was ticked, otherwise it will be empty).
So when you test tp send the array, just check if the first value of the array is equal to on.Code:if ($sendcopy[0] == "on") {You might even just be able to see if the variable exists as if they don’t check the box nothing should get passed through. So this might even work,
Code:if ($sendcopy) {Again, im still learning with php so someone else will have to check this but there is no harm in testing it out, please let us know if it does work.
Also while im on it, i don’t think you need to use the strip slashes on the checkbox post as the user can’t alter the value.
August 18, 2010 at 3:47 pm #81746brianatlarge
MemberOk… I think my code works because I just tried some different email addresses and it sends correctly, it’s just the emails aren’t being delivered to my domain email address.
Is it possible that it ignores emails that are sent to and from the same address?
August 19, 2010 at 5:24 am #81772Rob MacKay
ParticipantOn the checkboxes – forms only send array’ed data if you tell them to… for example:
<input type="checkbox" name="data[value1][checkbox]" value="1" />
would output the value – in this case "1" if you did:
$data = $_POST;
echo $data[value1][checkbox];
Other than that it would just be a normal value stored within the global post or get array.
And the next part – if it works with another email address, are you SURE you have put the email address in right? Yea I know, sorry, but it’s normally the silly things that I miss…
September 13, 2010 at 3:17 pm #79904brianatlarge
MemberI think I found out what the problem was: http://www.reconception.com/index.php/joelparent/114-google-apps–media-temple-hosted-dv-35–broken-emailing-from-web-forms
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.