...

View Full Version : PHP email headers a little screwed up??? HELP!



skcin7
06-01-2011, 10:08 AM
I'm having a problem with PHP mail headers. At least that's what I think the problem is.

I have a form on a website. When a user submits the form, it sends an email to MY email address. I log into email and reply to it. This is fine. HOWEVER, if the user wants to reply back, the email address to reply back to will be their own email address, NOT mine.

For example.
User goes to my website, posts in the contact form, which sends an email to me
I go to my mail and click "reply". The email the user entered shows up as the reply email, so I send them an email
User checks his email, sees my message, and clicks "reply", but HIS OWN email address shows up as the reply email, NOT mine again

I think this is a problem with the PHP mail headers. My code looks like this:



//Create headers for HTML mail
$headers = "MIME-Version: 1.0" . "\r\n"; //To send HTML mail, the Content-type header must be set
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n"; //This is also for HTML mail
$headers .= 'From: ' . $name . ' <' . $email . '>' . "\r\n";
$headers .= 'To: Nicholas Morgan <morgan60@students.rowan.edu>' . "\r\n";

$msg .= 'This email is to inform you of a new message posted from the contact form at ' . APPLICATION_URL . 'contact.php. The content of the message is as follows.<br /><br />';
$msg .= '<div style="padding:10px; border-left:1px #cccccc solid;">';
$msg .= 'Message written by ' . $name . ':<br /><br >';
$msg .= $message;
$msg .= '</div>';

//Send an email to me to alert me that somebody has sent me a message
mail("morgan60@students.rowan.edu", $subject, $msg, $headers);

krypton
06-01-2011, 01:25 PM
I'm having a problem with PHP mail headers. At least that's what I think the problem is.

I have a form on a website. When a user submits the form, it sends an email to MY email address. I log into email and reply to it. This is fine. HOWEVER, if the user wants to reply back, the email address to reply back to will be their own email address, NOT mine.

For example.
User goes to my website, posts in the contact form, which sends an email to me
I go to my mail and click "reply". The email the user entered shows up as the reply email, so I send them an email
User checks his email, sees my message, and clicks "reply", but HIS OWN email address shows up as the reply email, NOT mine again

I think this is a problem with the PHP mail headers. My code looks like this:



//Create headers for HTML mail
$headers = "MIME-Version: 1.0" . "\r\n"; //To send HTML mail, the Content-type header must be set
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n"; //This is also for HTML mail
$headers .= 'From: ' . $name . ' <' . $email . '>' . "\r\n";
$headers .= 'To: Nicholas Morgan <morgan60@students.rowan.edu>' . "\r\n";

$msg .= 'This email is to inform you of a new message posted from the contact form at ' . APPLICATION_URL . 'contact.php. The content of the message is as follows.<br /><br />';
$msg .= '<div style="padding:10px; border-left:1px #cccccc solid;">';
$msg .= 'Message written by ' . $name . ':<br /><br >';
$msg .= $message;
$msg .= '</div>';

//Send an email to me to alert me that somebody has sent me a message
mail("morgan60@students.rowan.edu", $subject, $msg, $headers);

i got contact.php codes which i use in my site. try this code and edit it as ur needs.it working fine and no error u will get.




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>My Email Form</title>
</head>
<body>

<!--
Php Contact Form
-->

<?php

include ("conf.php");

connectdb();

echo "<head>";
echo "<title>your site name</title>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../style/simplestyle.css\">";
echo "</head>";
echo "<body>";

// OPTIONS - PLEASE CONFIGURE THESE BEFORE USE!

$yourEmail = "owner@mysite.com"; // the email address you wish to receive these mails through
$yourWebsite = "www.mysite.com"; // the name of your website
$maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4


function isBot() {
$bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot");
$isBot = false;

foreach ($bots as $bot)
if (strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
$isBot = true;

if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ")
$isBot = true;

return $isBot;
}

if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (isBot())
exit("Bots not allowed.</p>");

function clean($data) {
$data = trim(stripslashes(strip_tags($data)));
return $data;
}

// lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score..
// score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam :)
$points = (int)0;

$badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "cum", "cunilingus", "cunillingus", "cunnilingus", "****", "ejaculate", "***", "felatio", "fellatio", "****", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "porn", "pussies", "pussy", "spunk", "xxx", "viagra", "phentermine", "tramadol", "adipex", "advai", "alprazolam", "ambien", "ambian", "amoxicillin", "antivert", "blackjack", "backgammon", "texas", "holdem", "poker", "carisoprodol", "ciara", "ciprofloxacin", "debt", "dating", "porn", "link=", "voyeur");
$exploits = array("content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript");

foreach ($badwords as $word)
if (strpos($_POST['comments'], $word) !== false)
$points += 2;

foreach ($exploits as $exploit)
if (strpos($_POST['comments'], $exploit) !== false)
$points += 2;

if (strpos($_POST['comments'], "http://") === true || strpos($_POST['comments'], "www.") === true)
$points += 2;
elseif (isset($_POST['nojs']))
$points += 1;
elseif (preg_match("/(<.*>)/i", $_POST['comments']))
$points += 2;
elseif (strlen($_POST['name']) < 3)
$points += 1;
elseif (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500))
$points += 2;
// end score assignments

if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comments'])) {
$error_msg .= "Name, e-mail and comments are required fields. \n";
} elseif (strlen($_POST['name']) > 15) {
$error_msg .= "The name field is limited at 15 characters. Your first name or nickname will do! \n";
} elseif (!ereg("^[A-Za-z' -]*$", $_POST['name'])) {
$error_msg .= "The name field must not contain special characters. \n";
} elseif (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,6})$",strtolower($_POST['email']))) {
$error_msg .= "That is not a valid e-mail address. \n";
} elseif (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i', $_POST['url']))
$error_msg .= "Invalid website url.";

if ($error_msg == NULL && $points <= $maxPoints) {
$subject = "Automatic Form Email";

$message = "You received this e-mail message through your website: \n\n";
foreach ($_POST as $key => $val) {
$message .= ucwords($key) . ": $val \r\n";
}
$message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n";
$message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";
$message .= 'Points: '.$points;

if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
$headers = "From: $yourEmail \r\n";
$headers .= "Reply-To: {$_POST['email']}";
} else {
$headers = "From: $yourWebsite <$yourEmail> \r\n";
$headers .= "Reply-To: {$_POST['email']}";
}

if (mail($yourEmail,$subject,$message,$headers)) {
echo '<p>Your mail was successfully sent to site owner.</p>';
} else {
echo '<p>Your mail could not be sent this time.</p>';
}
}
}
function get_data($var) {
if (isset($_POST[$var]))
echo htmlspecialchars($_POST[$var]);
}
if ($error_msg != NULL) {
echo '<p><strong style="color: red;">ERROR:</strong><br />';
echo nl2br($error_msg) . "</p>";
}
?>


<form action="contact.php" method="post">
<noscript>
<p><input type="hidden" name="nojs" id="nojs" /></p>
</noscript>
<p>
<label for="name">Your Name:</label>
<input type="text" name="name" id="name" value="<?php get_data("name"); ?>" /><br />


<label for="email">Your E-mail:</label>
<input type="text" name="email" id="email" value="<?php get_data("email"); ?>" /><br />
<label for="comments">Your Problem:</label>
<textarea name="comments" id="comments" rows="5" cols="20"><?php get_data("comments"); ?></textarea><br />
</p>
<p>
<input type="submit" name="submit" id="submit" value="Send" />
</p>
</form>





</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum