• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

How can i sent a comment directly to the email address?

Dear Experts,

Here is what I want on my website. I have a simple form (textarea) and a submit button on my page.
And whenever a comment is submitted I want that comment to go to my email address xyz@gmail.com.
How can I do that ?

Thank you inadvance
<form method="post" action="support.html" >
  Send your comments to our email address:<br />
  <textarea name="comments" id="comments">
  
  </textarea><br />
  <input type="submit" value="Submit" />

</form>

Open in new window

0
kate2001
Asked:
kate2001
  • 3
1 Solution
 
Jagadishwor DulalBraces MediaCommented:
You will need a serverside script like php, asp or any other which can post your comment to direct in email like below I am showing you an example of php.
<?php
if(isset($_POST['submit'])){
$to = "xyz@gmail.com";
$subject = "Comment";
$comment = $_POST['comments'];
$headers = "From: comment@webpage.com" ;

mail($to,$subject,$comment,$headers);
?>

Open in new window

0
 
leakim971PluritechnicianCommented:
Using the PHP code of jagadishdulal and jQuery (readability and simplicity) :

(the comments is submitted silently with Ajax)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$("form").submit(function(e) {
			e.preventDefault();
			$.post("jagadishdulal.php", $("form").serializeArray(), function() {
				alert("Thanks for your comments!!!");
			});
		});
	});
</script>
</head>
<body>
<form id="myform" method="post" action="support.html" >
Send your comments to our email address:<br />
<textarea name="comments" id="comments"></textarea><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>

Open in new window

0
 
kate2001Author Commented:
jagadishdulal and leakim971,

Thank you so much for the help.

I have used your approach but it seems like the comment is not being send out to my email.

What am I missing here?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script language="javascript">
        $(document).ready(function() {
                $("form").submit(function(e) {
                        e.preventDefault();
                        $.post("sendsend.php", $("form").serializeArray(), function() {
                                alert("Thanks for your comments!!!");
                        });
                });
        });
</script>
</head>
<body>
<form id="form" method="post" action="support.html" >
Send your comments to our email address:<br />
<textarea name="comments" id="comments"></textarea><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>

Open in new window

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
if(isset($_POST['submit'])){
$to = "xyz@gmail.com";
$subject = "Comment";
$comment = $_POST['comments'];
$headers = "From: comment@webpage.com" ;

mail($to,$subject,$comment,$headers);
?>
</body>
</html>

Open in new window

0
 
leakim971PluritechnicianCommented:
You may found some answers here for example, section Setting extension-specific variables: http://www.techrepublic.com/article/a-tour-of-the-phpini-configuration-file-part-2/5272345
0
 
leakim971PluritechnicianCommented:
Thanks for the points!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now