943,589 Members | Top Members by Rank

Ad:
Mar 20th, 2008
0

AJAX Send Email Form with prototype and PHP

Expand Post »
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
Similar Threads
Reputation Points: 33
Solved Threads: 19
Nearly a Posting Virtuoso
mikeandike22 is offline Offline
1,496 posts
since May 2004
Mar 22nd, 2008
0

Re: AJAX Send Email Form with prototype and PHP

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. :-)
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Oct 28th, 2009
0
Re: AJAX Send Email Form with prototype and PHP
how can i sent the password after checking the email and send the email account of the person
Reputation Points: 10
Solved Threads: 0
Newbie Poster
imadbalcoh is offline Offline
1 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: javascript not working
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Problems in loading the external page to a div





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC