PHP receivce email help

Hi there! im new to php :-[ , im having problem when receiving email from enquiry from i have created below. i had create the form, after user click on submit, the information will store in mysql and send a copy to email account. My problem is, in the form i had ‘name’,‘email’,‘contact’, ‘subject’,‘message’ but i only receive ‘message’ from email,other information not receiving (no problem with mysql). i have tried few method like adding variable …it cant works as well. hope u guys able to help me. Thank you in advance :slight_smile:

[php]

Login Script <?php function insertData($msg) // <-- add rest $_post data here.. { // Connects to your Database mysql_connect("xxxxxx","xxxxxx","xxxxxx") or die(mysql_error()); mysql_select_db("xxxxxx_enquiry") or die(mysql_error()); // now we insert it into the database $insert = "INSERT INTO enquiry (name, email, cont_number, subject, msg) VALUES ('".$_POST['name']."', '".$_POST['email']."', '".$_POST['cont_number']."', '".$_POST['subject']."','".$_POST['msg']."')"; if($add_member = mysql_query($insert)) { sendMail(($_POST['msg']),($_POST['email'])); } } function sendMail($message) { $to = '[email protected]'; $from = 'From: xxxxx.com'; mail($to, "You have a new message", $message, $from); $message="Thank You !!
Form has been submitted"; } ?> <?php function error_bool($error, $field) { if($error[$field]) { print(""); } else { print(""); } } ////////////////// function show_form() { global $HTTP_POST_VARS, $_POST, $print_again, $error; ?>

Enquiry Form

<?php error_bool($error, "name"); ?> Name <?php error_bool($error, "email"); ?> Email
<tr><td>Contact No. </td><td>

:

<tr> 
  <td><th colspan=4 align="right">
  <input type="reset" value="Clear"><input type="submit" name="Submit" value="Submit"></td> 
  </th><td> </td> 
</tr> 
:" SIZE="33">
:" SIZE="33">
Subject

:

Your Message :
<?php }

if(isset($_POST[“Submit”]))
{
check_form();
}
else
{
show_form();
}

function check_email_address($email)
{
// First, we check that there’s one @ symbol, and that the lengths are right
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email))
{
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++)
{
if (!ereg("^(([A-Za-z0-9!#$%&’*+/=?^_{|}~-][A-Za-z0-9!#$%&'*+/=?^_{|}~.-]{0,63})|("[^(\|")]{0,62}"))$", $local_array[$i]))
{
return false;
}
}

if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) 
{ // Check if domain is IP. If not, it should be valid domain name 
	$domain_array = explode(".", $email_array[1]); 
	if (sizeof($domain_array) < 2) 
	{ 
		return false; // Not enough parts to domain 
	} 
	for ($i = 0; $i < sizeof($domain_array); $i++) 
	{ 
		if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) 
		{ 
			return false; 
		} 
	} 
} 
return true; 

}

function check_form()
{
global $_POST, $error, $print_again;
$error[‘name’] = false;
if($_POST[“name”]=="")
{
$error[‘name’] = true;
$print_again = true;
$message=“The name field is empty
”;
}

if(!check_email_address($_POST['email'])) 
{ 
	$error['email'] = true; 
	$print_again = true; 
	$message.="Either Field Empty or Invalid Email ID <br>"; 
} 

if($print_again) 
{ 
	show_form();
} 
else 
{ 
	show_form(); 
	insertData($_POST['msg']); // <-- call the function (add the rest of post data here.)
	//$message="Thank You !! <br> Form has been submitted"; // <-- move this to the sendMail function
} 
echo "$message"; 

}
?>

[/php]

Hi,

Try this this will help you.

function insertData($msg) // <-- add rest $_post data here…
{
// Connects to your Database
mysql_connect(“xxxxxx”,“xxxxxx”,“xxxxxx”) or die(mysql_error());
mysql_select_db(“xxxxxx_enquiry”) or die(mysql_error());
// now we insert it into the database
$insert = “INSERT INTO enquiry (name, email, cont_number, subject, msg)
VALUES (’”.$_POST[‘name’]."’, ‘".$_POST[‘email’]."’, ‘".$_POST[‘cont_number’]."’,
‘".$_POST[‘subject’]."’,’".$_POST[‘msg’]."’)";
if($add_member = mysql_query($insert))
{
$msg = “Hello Admin,
you have recieved this email from”. $_POST[‘name’] . “
”;
$msg .= “Contact No:”. $_POST[‘cont_number’]."
";
$msg .= $_POST[‘msg’];
sendMail($msg, $_POST[‘subject’], $_POST[‘email’]);
}
}
function sendMail($message, $subject, $from)
{
$to = ‘your admin email account’;
mail($to, $subject, $message, $from);
$message = “Thank You !!
Form has been submitted”;
}

Hi sarthakpatel ! Thank you so much :smiley: i’m still new to PHP and the changes you make is easy for me to understand without confusing :-* THANK YOU

Sponsor our Newsletter | Privacy Policy | Terms of Service