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
Reply

Join Date: May 2004
Posts: 1,478
Reputation: mikeandike22 is an unknown quantity at this point 
Solved Threads: 18
mikeandike22's Avatar
mikeandike22 mikeandike22 is offline Offline
Nearly a Posting Virtuoso

AJAX Send Email Form with prototype and PHP

 
0
  #1
Mar 20th, 2008
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
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <form method"post" onsubmit="return false;">
  2. <label>Your Email:<br /><input type="text" name="email" id="email" /></label><br />
  3. <label>Subject:<br /><input type="text" name="subject" id="subject" style="width:500px;" /></label><br />
  4. <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 />
  5. <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()" />
  6. </form>

PHP
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2. $mail['to'] = 'business@caffeinatedcustoms.com';
  3. $mail['from'] = $_POST['email'];
  4. $mail['subject'] = $_POST['subject'];
  5. $mail['message'] .= $_POST['message'];
  6. $mail['header'] = 'From: '.$_POST['Name'].'<'. $mail['from'] . ">\r\n";
  7.  
  8. $mail['status'] = @mail($mail['to'], $mail['subject'], $mail['message'], $mail['header']);
  9. if ($mail['status'] == false) {
  10. echo 'Failed to send mail to ' . $mail['to'] . '.<br>Error: ' . error_get_last();
  11. exit;
  12. }
  13. else{
  14. echo 'Thank You we will Resond Soon';
  15. }
  16. ?>

Javascript
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript" src="prototype.js"></script>
  2. <script>
  3.  
  4. function sendRequest() {
  5. new Ajax.Request("sendmail.php",
  6. {
  7. method: 'post',
  8. postBody: 'message='+ $F('message'),
  9. onComplete: showResponse
  10. });
  11. }
  12.  
  13. function showResponse(req){
  14. $('show').innerHTML= req.responseText;
  15. }
  16. </script>

Thanks in advance
My Daniweb Blog: This,That, and Everything Else (Blog contest winner)

GetFirefox!
GetOpera!






Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: AJAX Send Email Form with prototype and PHP

 
0
  #2
Mar 22nd, 2008
This forum is basically for generic Javascript questions which don't necessarily refer to a particular library. This question would be more appropriate in the Prototype.js forums where you have better chances of getting help. :-)
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 1
Reputation: imadbalcoh is an unknown quantity at this point 
Solved Threads: 0
imadbalcoh imadbalcoh is offline Offline
Newbie Poster
 
0
  #3
30 Days Ago
how can i sent the password after checking the email and send the email account of the person
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC