Solved

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

Posted on 2011-03-10
5
197 Views
Last Modified: 2012-05-11
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
Comment
Question by:kate2001
  • 3
5 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 35106210
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
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 35113570
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
 

Author Comment

by:kate2001
ID: 35121409
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
 
LVL 82

Expert Comment

by:leakim971
ID: 35123435
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
 
LVL 82

Expert Comment

by:leakim971
ID: 35380100
Thanks for the points!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question