sk8ertim Posted November 29, 2007 Share Posted November 29, 2007 Hi all, well this is the PHP code <?php$to = $_REQUEST['sendto: admin@skating-camp.com'];$from = $_REQUEST['surname'];$name = $_REQUEST['firstname'];$headers = "From: $firstname";$subject = "Web Contact Data";$fields = array();$fields{"firstname"} = "firstname";$fields{"surname"} = "surname";$fields{"birthday"} = "birthday";$fields{"parent_name"} = "parent_name";$fields{"address"} = "address";$fields{"phone"} = "phone";$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }if($firstname == '') {print "Вы не вставели своё имя.";}else {if($name == '') {print "You have not entered a name, please go back and try again";}else {$send = mail($to, $subject, $body, $headers);if($send){header( "Location: http://www.skating-camp.com/index.html" );}else{print "We encountered an error sending your mail, please notify admin@skating-camp.com"; }}}?> But I got a problem, whenever I try to send the form out to my email I get an error message. http://www.skating-camp.com/OPLATA.html thats the form in my site.By the way, I got the problem with the gray box fixed. And all cause of your ppls' help.I LOVE THIS PLACE! :wub: Link to comment Share on other sites More sharing options...
TehBlizzy Posted November 29, 2007 Share Posted November 29, 2007 Have you tried using $_POST instead of request? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 29, 2007 Share Posted November 29, 2007 1. You're not giving it a valid "to" address. I really doubt there is an element in the $_REQUEST array called "sendto: admin@skating-camp.com".2. The From header is trying to use a variable called $firstname. First off, that variable is not defined. Secondly, the From header needs to be a valid email address according to the RFC. The formatting of this string must comply with » RFC 2822. Some examples are: user@example.comuser@example.com, anotheruser@example.comUser <user@example.com>User <user@example.com>, Another User <anotheruser@example.com>Your array syntax is also incorrect here:$fields{"firstname"} = "firstname";You use square brackets, not curly brackets. Link to comment Share on other sites More sharing options...
sk8ertim Posted November 29, 2007 Author Share Posted November 29, 2007 1. You're not giving it a valid "to" address. I really doubt there is an element in the $_REQUEST array called "sendto: admin@skating-camp.com".2. The From header is trying to use a variable called $firstname. First off, that variable is not defined. Secondly, the From header needs to be a valid email address according to the RFC.Your array syntax is also incorrect here:$fields{"firstname"} = "firstname";You use square brackets, not curly brackets.OK, I didnt understand anything you said. :) Link to comment Share on other sites More sharing options...
justsomeguy Posted November 29, 2007 Share Posted November 29, 2007 I don't really know how to restate it more clearly. You need to give the mail function a valid email address to send to, you're not doing that. I assume the from address is also not valid. And lines like this:$fields{"firstname"} = "firstname";should be like this:$fields["firstname"] = "firstname";Print the $to and $headers variables to see what you're telling the mail function to do. Link to comment Share on other sites More sharing options...
sk8ertim Posted November 29, 2007 Author Share Posted November 29, 2007 I don't really know how to restate it more clearly. You need to give the mail function a valid email address to send to, you're not doing that. I assume the from address is also not valid. And lines like this:$fields{"firstname"} = "firstname";should be like this:$fields["firstname"] = "firstname";Print the $to and $headers variables to see what you're telling the mail function to do.Well I did this $fields["firstname"] = "firstname";but i got NO IDEA what to do with the rest. :) Link to comment Share on other sites More sharing options...
justsomeguy Posted November 29, 2007 Share Posted November 29, 2007 Then you're not paying attention. Look at this block:$fields{"firstname"} = "firstname";$fields{"surname"} = "surname";$fields{"birthday"} = "birthday";$fields{"parent_name"} = "parent_name";$fields{"address"} = "address";$fields{"phone"} = "phone";The {} are used to denote a block of code or a scope, they are not for arrays. Array syntax uses []. So all of the {} in that code need to be replaced with []. And you need to debug the call to the mail function. You have this:$send = mail($to, $subject, $body, $headers);Print what you are sending to the mail function so that you can see what the problem is. echo "To: {$to}<br>Subject: {$subject}<br>Body: {$body}<br>Headers: {$headers}"; If you're just starting out with PHP you will want to read the first several sections of the language reference online. Read at least up to the section on functions, it will give you a better handle on things:http://www.php.net/manual/en/langref.phpIt's a lot easier to learn the language first and then use it instead of the other way around. Link to comment Share on other sites More sharing options...
sk8ertim Posted November 29, 2007 Author Share Posted November 29, 2007 Then you're not paying attention. Look at this block:$fields{"firstname"} = "firstname";$fields{"surname"} = "surname";$fields{"birthday"} = "birthday";$fields{"parent_name"} = "parent_name";$fields{"address"} = "address";$fields{"phone"} = "phone";The {} are used to denote a block of code or a scope, they are not for arrays. Array syntax uses []. So all of the {} in that code need to be replaced with []. And you need to debug the call to the mail function. You have this:$send = mail($to, $subject, $body, $headers);Print what you are sending to the mail function so that you can see what the problem is.echo "To: {$to}<br>Subject: {$subject}<br>Body: {$body}<br>Headers: {$headers}"; If you're just starting out with PHP you will want to read the first several sections of the language reference online. Read at least up to the section on functions, it will give you a better handle on things:http://www.php.net/manual/en/langref.phpIt's a lot easier to learn the language first and then use it instead of the other way around. Thank you for helping. I understud this part and changed it.$fields = array();$fields["firstname"] = "firstname";$fields["surname"] = "surname";$fields["birthday"] = "birthday";$fields["parent_name"] = "parent_name";$fields["address"] = "address";$fields["phone"] = "phone";$fields{"phone"} = "phone"; Link to comment Share on other sites More sharing options...
justsomeguy Posted November 30, 2007 Share Posted November 30, 2007 Add that other line of code either right before or right after the mail function to check on the data you're using. Make sure the "to" email and the headers are correct. Link to comment Share on other sites More sharing options...
sk8ertim Posted November 30, 2007 Author Share Posted November 30, 2007 Add that other line of code either right before or right after the mail function to check on the data you're using. Make sure the "to" email and the headers are correct.What code do I use to do the check up on data??? Link to comment Share on other sites More sharing options...
Synook Posted November 30, 2007 Share Posted November 30, 2007 Echo it e.g. echo $to; and if you don't see what you expect something has gone wrong. And by the way, looking at the second line of your code, do you really have a field with the name sendto: admin@skating-camp.com? Don't you mean $to = "admin@skating-camp.com"; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.