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

<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

<?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

<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 ;)

Recommended Answers

All 2 Replies

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. :-)

how can i sent the password after checking the email and send the email account of the person

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.