Jump to content

mailform


toker

Recommended Posts

Hi - been trying for days to get this to work but it only works half - it sends the email to info@website.com - I want to send a message to the email sender as well but - it used to work before - it just ain't going. What am I missing.

 

<?php

 

//create short variable names

$name=$_POST['name'];

$email=$_POST['email'];

$subject=$_POST['subject'];

$message=$_POST['message'];

 

$name=trim($name);

$email=trim($email);

$subject=StripSlashes($subject);

$message=StripSlashes($message);

 

 

    //clear the variables

    $name='';

    $email='';

    $subject='';

    $message='';

 

if(!empty($HTTP_POST_VARS['name']) || !empty($HTTP_POST_VARS['email']))

{

$to = "info@website.com";

$subject = "website name";

$body .= "\n\n";

$body .= "This email is send by: " . $HTTP_POST_VARS['name'] . " \n\n<" . $HTTP_POST_VARS['email']  . ">\n\n";

$body .= "" . $HTTP_POST_VARS['message'] . "\n";

$body .= "\n";

 

$header = "From: " . $HTTP_POST_VARS['name'] . " <" . $HTTP_POST_VARS['email'] . ">\n";

$header .= "Reply-To: " . $HTTP_POST_VARS['name'] . " <" . $HTTP_POST_VARS['email'] . ">\n";

$header .= "X-Mailer: PHP/" . phpversion() . "\n";

$header .= "X-Priority: 1";

if(@mail($to, $subject, $body, $header))

{

"output=sent";

} else {

"output=error";

}

} else {

"output=error";

}

 

///////////////

 

$to = ($HTTP_POST_VARS['email']);

$subject = "website email";

$body = "Dear " . ($HTTP_POST_VARS['name']);

$body .= ",";

$body .= "\n\nThank you for your email. \n\nWe will surely read it, but because we receive so many mails, the answer\nsometimes may take a couple of days.\n\nToker \n";

$body .= "\n\n";

 

$header .= "X-Mailer: PHP/" . phpversion() . "\n";

$header .= "X-Priority: 1";

if(@mail($to, $subject, $body, $header))

 

//redirect to the 'thank you' page

header('Location: contact_ok.html');

?>

Link to comment
Share on other sites

Try the following. There were 2 or 3 lines i change because I assumed you wanted to echo a statement, but they didn't make sense. You can't just have 

"output=sent";

it wrong.

 

Try the following code and tell me how it goes.

 

<?php

//Create Variable Names
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$subject = StripSlashes($_POST['subject']);
$message = StripSlashes($_POST['message']);
   
//Clear variables
$name = "";
$email = "";
$subject = "";
$message = "";   
   
if(!empty($HTTP_POST_VARS['name']) || !empty($HTTP_POST_VARS['email'])){

$to = "info@website.com";   
$subject = "website name";
$body .= "\n\n";
$body .= "This email is send by: " . $HTTP_POST_VARS['name'] . " \n\n<" . $HTTP_POST_VARS['email']  . ">\n\n";
$body .= "" . $HTTP_POST_VARS['message'] . "\n";
$body .= "\n";

$header = "From: " . $HTTP_POST_VARS['name'] . " <" . $HTTP_POST_VARS['email'] . ">\n";
$header .= "Reply-To: " . $HTTP_POST_VARS['name'] . " <" . $HTTP_POST_VARS['email'] . ">\n";
$header .= "X-Mailer: PHP/" . phpversion() . "\n";
$header .= "X-Priority: 1";

		if(mail($to, $subject, $body, $header)){
			echo "Sent";
			}
		else {
			echo "Error";
		}
} 	
else {
	echo "Error";
}
   


$to = ($HTTP_POST_VARS['email']);   
$subject = "website email";
$body = "Dear " . ($HTTP_POST_VARS['name']);
$body .= ",";
$body .= "\n\nThank you for your email. \n\nWe will surely read it, but because we receive so many mails, the answer\nsometimes may take a couple of days.\n\nToker \n";
$body .= "\n\n";
   
$header .= "X-Mailer: PHP/" . phpversion() . "\n";
$header .= "X-Priority: 1";
if(mail($to, $subject, $body, $header))
   
//redirect to the 'thank you' page
header('Location: contact_ok.html');
?>

Link to comment
Share on other sites

Thanx Donald this does the trick

 

one more question - I would like to redirect after sending to

 

//redirect to the 'thank you' page

header('Location: contact_ok.html');

 

now I get the sent message - how do I change this

 

 

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.