| | |
AJAX Send Email Form with prototype and PHP
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hey Im trying to send an email with PHP. but Im using ajax to load all my pages So i dont want to disrupt that flow by having the page refresh when you hit submit..I just want it to be like loading and then echo Thank you or something. Here is my current code.
HTML
PHP
Javascript
Thanks in advance
HTML
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<form method"post" onsubmit="return false;"> <label>Your Email:<br /><input type="text" name="email" id="email" /></label><br /> <label>Subject:<br /><input type="text" name="subject" id="subject" style="width:500px;" /></label><br /> <label>Message:<br /><input type="text" name="message" id="message" style="width:500px;height:200px;background-color:#DFB782;color:#000;border:1px solid #462401;font-weight:bold;" /></label><br /> <input type="submit" value="Send" style="background-color:#DFB782;color:#000;border:1px solid #462401;font-weight:bold;margin-top:5px;padding:5px;font-size:18px;" onClick="sendRequest()" /> </form>
PHP
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<?php $mail['to'] = 'business@caffeinatedcustoms.com'; $mail['from'] = $_POST['email']; $mail['subject'] = $_POST['subject']; $mail['message'] .= $_POST['message']; $mail['header'] = 'From: '.$_POST['Name'].'<'. $mail['from'] . ">\r\n"; $mail['status'] = @mail($mail['to'], $mail['subject'], $mail['message'], $mail['header']); if ($mail['status'] == false) { echo 'Failed to send mail to ' . $mail['to'] . '.<br>Error: ' . error_get_last(); exit; } else{ echo 'Thank You we will Resond Soon'; } ?>
Javascript
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script type="text/javascript" src="prototype.js"></script> <script> function sendRequest() { new Ajax.Request("sendmail.php", { method: 'post', postBody: 'message='+ $F('message'), onComplete: showResponse }); } function showResponse(req){ $('show').innerHTML= req.responseText; } </script>
Thanks in advance
![]() |
Similar Threads
- AJAX generated <select> and FIREFOX (JavaScript / DHTML / AJAX)
- Ajax calls wont work in FireFox! (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: how to load a page in a div tag
- Next Thread: Problems in loading the external page to a div
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array browser bug captchaformproblem cart checkbox child class close codes createrange() css cursor date debugger decimal dependent design disablefirebug dom dropdown editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming progressbar prototype redirect runtime safari scale scriptlets scroll search security shopping size software toggle unicode w3c web wysiwyg \n






