Hi all i need to recieve comment on my page and i need the message to go to my mail address can any one help me how to do it?

thanx

Recommended Answers

All 2 Replies

Check mail function in php.

I wrote this simple form script with PHP processing and it's beautiful. Copy and paste this code into the portion of your web page where you want the form to appear (it can be HTML or PHP web page, that is, you can save this file as comments.html or as comments.php):

<td width="411" valign="top"><form enctype="multipart/form-data" action="process.php" method="post">

<table style="border-collapse: collapse" width="411" height="293" cellspacing="1" cellpadding="5" border="1" align="center">
  <tbody><tr align="left"><td width="10%" height="17" bgcolor="#b5cbef" background="../tile_back.gif" colspan="2" bordercolor="#FFFFFF"><p><font size="2" face="Verdana" color="#ffffff"><strong>
    <!--- You can add a form title here ---->   
    </strong></font><strong><font size="2" face="Verdana" color="#000066"> </font></strong>
    </p>
  </p></td></tr><tr>
    <td width="100%" height="16" bgcolor="#b5cbef" background="../tile_sub.gif" bordercolor="#FFFFFF" colspan="2"><p><font size="2" face="Verdana"><strong><font size="2" face="Verdana" color="#000066">
              <!--- You can add a brief form description here---->
      <br>
    </strong></font></p></td></tr><tr><td width="10%" height="16" bgcolor="#d6dfef" colspan="2" bordercolor="#FFFFFF"><font size="1" face="Verdana">Please fill in all fields marked with a <font color="#ff0000">*</font></font></td></tr><tr><td width="100" height="30" bgcolor="#eff3f7" align="right" bordercolor="#FFFFFF"><font size="2" face="Verdana">Name:</font></td><td width="469" height="30" bgcolor="#eff3f7" bordercolor="#FFFFFF"><font face="Verdana">
<input name="Name" type="text" size="40">
<font color="#ff0000">*</font></font></td></tr><tr><td width="100" height="30" bgcolor="#eff3f7" align="right" bordercolor="#FFFFFF"><font size="2" face="Verdana">Email:</font></td><td width="469" height="30" bgcolor="#eff3f7" bordercolor="#FFFFFF"><font face="Verdana">
<input name="Email" type="text" size="40">
<font color="#ff0000">*</font></font></td></tr><tr><td width="100" height="30" bgcolor="#eff3f7" align="right" bordercolor="#FFFFFF"><font size="2" face="Verdana">Web Site:</font></td><td width="469" height="30" bgcolor="#eff3f7" bordercolor="#FFFFFF"><font face="Verdana">
<input name="WebSite" type="text" size="40">
</font></td></tr><tr><td width="100" height="30" bgcolor="#eff3f7" align="right" bordercolor="#FFFFFF"><font size="2" face="Verdana">Message:</font></td><td width="469" height="30" bgcolor="#eff3f7" bordercolor="#FFFFFF"><font face="Verdana"><textarea name="Message" rows="4" cols="30"></textarea>
<font color="#ff0000">*</font></font></td></tr><tr>
  <td width="10%" height="25" colspan="2" align="center" background="../tile_sub.gif" bgcolor="#b5cbef"><font size="2" face="Verdana">
  <input type="submit" value="Submit Form">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <input type="reset" value="Reset Form">
  </font></td>
</tr></tbody></table>
      </form>

Now that you've got the form in place on your page, let's go over to its processing in PHP. Copy the PHP code below and save the file as process.php

<?php
echo "<title>yourdomain.com: Comment Process</title>";
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','Name');
pt_register('POST','Email');
pt_register('POST','WebSite');
pt_register('POST','Message');
$Message=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Message);if($Name=="" || $Email=="" || $Message=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){
$error.="<li>Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Name: ".$Name."
Email: ".$Email."
Web Site: ".$WebSite."
Message: ".$Message."
";
$message = stripslashes($message);
mail("youremailaddress@yourdomain.com","A new comment has been posted",$message,"From: Form Processor");
$make=fopen("data.dat","a");
$to_put="";
$to_put .= $Name."|".$Email."|".$WebSite."|".$Message."
";
fwrite($make,$to_put);
echo '<meta http-equiv="refresh" content="0;url=thankyou.html" />'; 
}
?>

In the above PHP file remember to modify: (1) Replace yourdomain.com with your real domain name. (2) Replace youremailaddress@yourdomain.com with your real email address.

Next step is that you have to create a simlpe web page and name it thankyou.html . This is the page where a visitor will be sent to after successful submission of your form. This should be a simple thank you page. The page may only contain: "Thank you for signing our comments form". Anything you like!

Then copy the code below and save it as global.inc.php :

<?php

function pt_register()
{
$num_args = func_num_args();
$vars = array();

if ($num_args >= 2) {
$method = strtoupper(func_get_arg(0));

if (($method != 'SESSION') && ($method != 'GET') && ($method != 'POST') && ($method != 'SERVER') && ($method != 'COOKIE') && ($method != 'ENV')) {
die('The first argument of pt_register must be one of the following: GET, POST, SESSION, SERVER, COOKIE, or ENV');
}

$varname = "HTTP_{$method}_VARS";
global ${$varname};

for ($i = 1; $i < $num_args; $i++) {
$parameter = func_get_arg($i);

if (isset(${$varname}[$parameter])) {
global $$parameter;
$$parameter = ${$varname}[$parameter];
}

}

} else {
die('You must specify at least two arguments');
}

}

?>

Finally upload the above four files to the same directory on the server where your website resides. This script will not submit the form, if your visitor doesn't fill any of the required fields properly. Good luck and get back to me if you need more assistance on this.

Hi all i need to recieve comment on my page and i need the message to go to my mail address can any one help me how to do it?

thanx

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.