Jump to content

Mail function not working & need help showing conformation mesage


Marcus2000

Recommended Posts

Hi people, please can some one help me out with a bit of php for the 'mail function'?

 

All i want to do is have the end user fill out the form, hit submit then either have the user directed to a thank you page or have pop up

message stating that the information has been sent.

 

At the moment the code i have does not seem to be sending the mail and aditionally i have no idea where or how to start writing the code for the thank you page or the

conformation pop up message.

 

Please can some one show me the light on this one, i am really just starting out with php and finding it real hard.

 

Anyway guys this is the code i have, please let us know what i'm doing wrong and what i need to add to it.

 

<?php
if(isset($_POST['submit'])) {

$to = "my_email@mydomain";
$subject = "Contact Form";

$name = 		$_POST['name'];
$comp_name = 	$_POST['company_name'];
$email = 		$_POST['email'];
$phone = 		$_POST['contact_number'];
$location = 	$_POST['location'];
$message = 		$_POST['message'];

$body = 		"From: $name\n E-Mail: $email\n Company Name: $comp_name\n Contact Number: $phone:\n Location: $location:\n Message:\n $message";

mail($to, $subject, $body); }


?>

 

 

Hope some one can help, many thanks in advance.

 

Cheers.

Link to comment
Share on other sites

you didn't post your contact form but i'll help on this one,

 

first put this at the top of the page your form is on:

Forgot to add that you need to make sure the thanks.php file is there because once they submit the form it will push them to that page, if there is an error then it will keep them on the form and you will need to add the code at the bottom of this post.

<?php
$err = "";
if (isset($_GET["send"] == 1)) {
$err = send_message($_POST);
if (!$err)
	header("Location: thanks.php");
	exit;
}
?>

make sure your form's action looks like this or close to it:

<form action="<?php echo $_SERVER["PHP_SELF"] . "?send=1"; ?>" method="post">

here is your new code, it should work just put it in a file and include it above the code above

<?php
function send_message($vars) {
	$email  = "my_email@mydomain.com";

	$body  = "From: " . $vars["name"] . "\n";
	$body .= "E-Mail: " . $vars["email"] . "\n";
	$body .= "Company Name: " . $vars["comp_name"] . "\n";
	$body .= "Contact Number: " . $vars["phone"] . "\n";
	$body .= "Location: " . $vars["location"] . "\n";
	$body .= "Message:\n " . $vars["message"] . "";

	$mail_err = mail($email, "Contact Form", $body, "From: " . $vars["email"] . "\nReply-To: " . $vars["email"] . "");

	if (!$mail_err) {
			$err = "The message could not be sent due to a problem with the mail server.";
	}
	return $err;
}
?>

 

Add this to your form somewhere, around the top of your form, it will output any error messages that come back from the code that I gave you.

<php
if ($err) {
echo "Error:<br />";
echo $err . "";
}
?>

intergrate it in your html somewhere or put it in a table, whatever you do make sure that it's there or the person won't know what errors are being kicked out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.