Solved

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

Posted on 2011-03-10
5
194 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now