How to create a php to stre the html form details

i cant able to send the submitted message in my form to my gmail id:

this is my html form which is perfectly working

<!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>IDECON2K19</title><script type="text/javascript">
function validate()
{
	if(document.signup.fname1.value=="")
	{
		alert("Please Enter First Name!");
		return false;
	}
	if(document.signup.lname1.value=="")
	{
		alert("Please Enter Last Name!");
		return false;
	}
	if(document.signup.uname1.value=="")
	{
		alert("Please Enter User Name!");
		return false;
	}
        if(document.signup.ph1.value=="")
	{
		alert("Please Enter phone no.!");
		return false;
	}
	if(document.signup.fname2.value=="")
	{
		alert("Please Enter First Name!");
		return false;
	}
	if(document.signup.lname2.value=="")
	{
		alert("Please Enter Last Name!");
		return false;
	}
	if(document.signup.uname2.value=="")
	{
		alert("Please Enter User Name!");
		return false;
	}
        if(document.signup.ph2.value=="")
	{
		alert("Please Enter phone no.!");
		return false;
	}
        if(!document.signup.agree.checked)
	{
		alert("Please enter the checkbok!");
		return false;
	}
	alert("Details Entered Successfully");
        display();
}
function display()
{
document.writeln('Registration Successfull!!!!');
}

</script>
</head>
<body align="center" background="images\wall.gif">
<table width="100%" height="100%">
<td colspan="2" width="15%">
</td>
<td colspan="1" background="images\new1.jpg" width="70%" height="100%" border="5%">
<h1 align="center"><font color="#0066ff" >IDECON2K19</font></h1>
<h2 align ="center"><font color="#0066ff">
REGISTRATION FORM</font></h2>
<form name="signup" onsubmit="return validate() method="post" action="form_php.php"">
<font face="verdana,arial,helvetica,sanserif" color="#660000" size="2">
<p>&nbsp;&nbsp; Person 1<br/>
*First Name:<input type="text" name="fname1" size="20">&nbsp;&nbsp;
*Last Name:<input type="text" name="lname1" size="20"></p>
<p style="border">&nbsp;&nbsp;
*Email:<input type="text" name="uname1" size="20">@gmail.com</p>
<p style="border">&nbsp;&nbsp;
Gender:<input type="radio" name="gen1" value="male">Male<input type="radio" name="gen" value="female">Female</p>
<p>&nbsp;&nbsp;
Department:<input type="text" name="dname" size="20"></p>
<p>&nbsp;&nbsp;
College Name:<input type="text" name="cname" size="20"></p>
<p>&nbsp;&nbsp;
Ph.no:<input type="text" name="ph1" size="11"></p>
<p>&nbsp;&nbsp; 
 Person 2<br/>
*First Name:<input type="text" name="fname2" size="20">&nbsp;&nbsp;
*Last Name:<input type="text" name="lname2" size="20"></p>
<p style="border">&nbsp;&nbsp;
*Email:<input type="text" name="uname2" size="20">@gmail.com</p>
<p style="border">&nbsp;&nbsp;
Gender:<input type="radio" name="gen2" value="male">Male<input type="radio" name="gen" value="female">Female</p>
<p>&nbsp;&nbsp;
Department:<input type="text" name="dname2" size="20"></p>
<p>&nbsp;&nbsp;
College Name:<input type="text" name="cname2" size="20"></p>
<p>&nbsp;&nbsp; 
Ph.no:<input type="text" name="ph2" size="11"></p>
<p>&nbsp;&nbsp; 
Idea Category:<select name="Idea Category">
<option selected>Select Category</option>
<option name="Country" value="IT based">IT Based</option>
<option name="Country" value="ECE&EEE based">ECE&EEE Based</option>
<option name="Country" value="Mech based">Mech Based</option>
<option name="Country" value="Civil&Other based">Civil&Other Based</option>
</select>
</p>
<p>&nbsp;&nbsp;
Idea Description:<br/>
<textarea name="message" rows="10" cols="30">Enter your idea description around 150 char here.</textarea>
<p align="center"><input type="checkbox" name="agree">registration fee 100Rs(for each) should be paid onspot</p>
<p align="center"><input type="submit" value="submit"><input type="reset" value="reset" /></p>
</font>
</form>
</td>
<td colspan="2" width="15%"></td>
</table>
</body>
</html>

this is my php code to recieve the email but its not working

<?php
if(isset($_POST['email'])) {
     
    // CHANGE THE TWO LINES BELOW
    $email_to = "idecon2k19@gmail.com";
     
    $email_subject = "website html form submissions";
     
    $first_name1 = $_POST['fname1']; // required
    $last_name1 = $_POST['lname1']; // required
    $email_from1 = $_POST['uname1']; // required
    $phone1 = $_POST['ph1']; // not required
    $gender1 = $_POST['gen1']; // required
    $dept1 = $_POST['dname1']; // required
    $collegename1 = $_POST['cname1']; // required
   
    $first_name2 = $_POST['fname2']; // required
    $last_name2 = $_POST['lname2']; // required
    $email_from2 = $_POST['uname2']; // required
    $phone2 = $_POST['ph2']; // not required
    $gender2 = $_POST['gen2']; // required
    $dept2 = $_POST['dname2']; // required
    $collegename2 = $_POST['cname2']; // required
     

    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "First Name1: ".clean_string($first_name1)."\n";
    $email_message .= "Last Name1: ".clean_string($last_name1)."\n";
    $email_message .= "Email1: ".clean_string($email_from1)."\n";
    $email_message .= "Telephone1: ".clean_string($phone1)."\n";
    $email_message .= "gender1: ".clean_string($gender1)."\n";
    $email_message .= "department1: ".clean_string($dept1)."\n";
    $email_message .= "college name1: ".clean_string($collegename1)."\n";
    
    $email_message .= "First Name2: ".clean_string($first_name2)."\n";
    $email_message .= "Last Name: ".clean_string($last_name2)."\n";
    $email_message .= "Email: ".clean_string($email_from2)."\n";
    $email_message .= "Telephone: ".clean_string($phone2)."\n";
    $email_message .= "gender: ".clean_string($gender2)."\n";
    $email_message .= "department: ".clean_string($dept2)."\n";
    $email_message .= "college name: ".clean_string($collegename2)."\n";
    
    $email_message .= "Idea category: ".clean_string($ideacategory)."\n";
    $email_message .= "Idea description: ".clean_string($ideadescription)."\n";
     
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>
 
<!-- place your own success html below -->

Thank you for contacting us. We will be in touch with you very soon.
 
<?php
}
die();
?>

pls someone help me to do it!!!

Stop supressing error messages. And try an wrapper class like PHPMailer. Try some other destination address.

Spot the difference:

$email_from1 = $_POST['uname1']; // required

and

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .

While you’re at it, it’s not a good idea to send emails “from” someone else’s address - a lot of proper SMTP servers will refuse to send emails from a domain they are not configured to handle. Send it from your own email address, and just use reply-to for the customers address.

Your form is confusing - the error message when you leave uname1 empty says “Please enter user name”, the prompt clearly says “Email”, and the field name is uname1. Using consistent names makes things easier.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.