artstarved Posted November 26, 2010 Share Posted November 26, 2010 Hey there, I was using this CSS 3 and jQuery form tutorial to build a form for my website. http://youhack.me/2010/07/22/create-a-fancy-contact-form-with-css-3-and-jquery/ (the PHP is near the bottom) It uses Ajax and Php to do the backend of the form, but in the tutorial there is not a $to. The form doesn't work because it has nowhere to go. Can someone please help me modify this code 'so I can include a send to email address: <?php $name = $_POST['name']; $email = $_POST['email']; $web = $_POST['web']; $body = $_POST['text']; if (!empty($name) & !empty($email) && !empty($body)) { $body = "Name:{$name}\n\nWebsite :{$web}\n\nComments:{$body}"; $send = mail($email, 'Contact Form Submission', $body, "From: {$email}"); if ($send) { echo 'true'; //if everything is ok,always return true , else ajax submission won't work } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/219937-ajax-form/ Share on other sites More sharing options...
Pikachu2000 Posted November 26, 2010 Share Posted November 26, 2010 Moving to Ajax Help . . . Quote Link to comment https://forums.phpfreaks.com/topic/219937-ajax-form/#findComment-1140046 Share on other sites More sharing options...
artstarved Posted November 27, 2010 Author Share Posted November 27, 2010 Seriously, any help or even a point in the right direction would be appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/219937-ajax-form/#findComment-1140139 Share on other sites More sharing options...
Pikachu2000 Posted November 27, 2010 Share Posted November 27, 2010 It isn't actually very clear where you're having problems. What do you mean "there is not a $to"? Quote Link to comment https://forums.phpfreaks.com/topic/219937-ajax-form/#findComment-1140141 Share on other sites More sharing options...
artstarved Posted November 27, 2010 Author Share Posted November 27, 2010 I'm sorry, that is not very clear. Basically there is now way to define a recipient for this email once it builds. That way when the script is executing the email does not actually send to anywhere(any specified email address). Any idea of how I might define a recipient and get this email to send? Quote Link to comment https://forums.phpfreaks.com/topic/219937-ajax-form/#findComment-1140278 Share on other sites More sharing options...
Pikachu2000 Posted November 27, 2010 Share Posted November 27, 2010 I'm certainly no AJAX expert, but if you're sending it to the same address all the time, you should be able to replace the $email variable in the mail() function call with your email address, or define $email as your address rather than assigning the value of $_POST['email'] to it. Quote Link to comment https://forums.phpfreaks.com/topic/219937-ajax-form/#findComment-1140342 Share on other sites More sharing options...
artstarved Posted November 27, 2010 Author Share Posted November 27, 2010 Thanks for the quick reply. I am understanding what you are saying, as it is right now the code sends the email back to address that you input. I have tried adding: <?php $to = $_POST['recipent@mail.com']; $name = $_POST['name']; $email = $_POST['email']; $web = $_POST['web']; $body = $_POST['text']; if (!empty($name) & !empty($email) && !empty($body)) { $body = "Name:{$name}\n\nWebsite :{$web}\n\nComments:{$body}"; $send = mail($email, 'Contact Form Submission', $body, "From: {$email}"); if ($send) { echo 'true'; //if everything is ok,always return true , else ajax submission won't work } } ?> But this doesn't fix the problem. It still behaves the same way. Then I tried this: <?php $to = "recipent@mail.com"; $name = $_POST['name']; $email = $_POST['email']; $web = $_POST['web']; $body = $_POST['text']; if (!empty($name) & !empty($email) && !empty($body)) { $body = "Name:{$name}\n\nWebsite :{$web}\n\nComments:{$body}"; $send = mail($email, 'Contact Form Submission', $body, "From: {$email}"); if ($send) { echo 'true'; //if everything is ok,always return true , else ajax submission won't work } } ?> But this doesn't fix the problem. It still behaves the same way. Lastly I tried what you just suggested: <?php $name = $_POST['name']; $email = $_POST['recipent@mail.com']; $web = $_POST['web']; $body = $_POST['text']; if (!empty($name) & !empty($email) && !empty($body)) { $body = "Name:{$name}\n\nWebsite :{$web}\n\nComments:{$body}"; $send = mail($email, 'Contact Form Submission', $body, "From: {$email}"); if ($send) { echo 'true'; //if everything is ok,always return true , else ajax submission won't work } } ?> This just breaks the function all together and it won't send the email all or complete the script. I feel like this is a no-brainer for someone who actually knows and uses PHP regularly. Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/219937-ajax-form/#findComment-1140361 Share on other sites More sharing options...
Pikachu2000 Posted November 27, 2010 Share Posted November 27, 2010 The first parameter in the mail() function is the address to which the email will be sent. With that in mind, $to = 'youremail@yourdomain.com'; //[sNIP] $send = mail($to, 'Contact Form Submission', $body, "From: {$email}"); Also, so you have the email address the user entered in the form inserted in the body of the email: $body = "Name:{$name}\n\nWebsite :{$web}\n\nComments:{$body}\n\nEmail Address: $email"; Quote Link to comment https://forums.phpfreaks.com/topic/219937-ajax-form/#findComment-1140368 Share on other sites More sharing options...
artstarved Posted November 27, 2010 Author Share Posted November 27, 2010 Thanks alot, its working awesome now! Quote Link to comment https://forums.phpfreaks.com/topic/219937-ajax-form/#findComment-1140374 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.