| | |
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 ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate array automatically beta box browser bug calendar captchaformproblem cart checkbox close codes column createrange() css cursor date debugger decimal dependent design dom download dropdown element embed enter error events firefox focus form frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsfile jsp libcurl listbox maps masterpage media menu microsoft mimic mp4 onmouseover paypal php player position post problem programming progressbar prototype redirect regex runtime safari scale scriptlets search security select size software sql text textarea unicode w3c website window windowofwords windowsxp






