toker Posted July 17, 2012 Share Posted July 17, 2012 Hi - been trying for days to get this to work but it only works half - it sends the email to [email protected] - 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 = "[email protected]"; $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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/265797-mailform/ Share on other sites More sharing options...
Donald. Posted July 17, 2012 Share Posted July 17, 2012 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 = "[email protected]"; $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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/265797-mailform/#findComment-1362054 Share on other sites More sharing options...
toker Posted July 17, 2012 Author Share Posted July 17, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/265797-mailform/#findComment-1362067 Share on other sites More sharing options...
toker Posted July 17, 2012 Author Share Posted July 17, 2012 Thanx a million - just did not see it - I am a zero with php but learning it all works - great Quote Link to comment https://forums.phpfreaks.com/topic/265797-mailform/#findComment-1362069 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.