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
https://forums.phpfreaks.com/topic/265797-mailform/
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
https://forums.phpfreaks.com/topic/265797-mailform/#findComment-1362054
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.