Forum Moderators: coopster
The code on the processor file is this:
<?
if (empty($_POST)) {
print "Error with form, please contact the webmaster.";
} else {
// Configuration Settings
$SendFrom = "Website Contact Form <info@example.co.uk>";
$SendTo = "info@example.co.uk";
$SubjectLine = "example";
$ThanksURL = "thankyou.html"; //confirmation page
$Divider = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($REMOTE_ADDR) . "\n$Divider\n";
foreach ($_POST as $Field=>$Value)
$MsgBody .= "$Field: $Value\n";
$MsgBody .= $Divider . "\n" . $HTTP_USER_AGENT . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe
// Send E-Mail and Direct Browser to Confirmation Page
mail($SendTo, $SubjectLine, $MsgBody, "From: " . $SendFrom);
header("Location: $ThanksURL");
}
?>
mail($SendTo, $SubjectLine, $MsgBody, "From: " . $SendFrom);
mail($SendFrom, $SubjectLine, $MsgBody, "From: " . $SendTo);
But this drives me nuts. :-) Not picking on you, everyone does it.
header("Location: $ThanksURL");
Why can't you make your response customized and helpful? Even as simple as
header("content-type:text/html");
echo "<p>Thank you for your inquiry, an email has been sent to $SendFrom. Below are the details of your inquiry.</p>";
echo $MsgBody;
exit;
It will need some work, you might have to add HTML headers to the emails for formatted HTML email (which will make them look better,) or go with <pre> on output response, and admittedly it's not all that helpful - but it CAN be, and this would at least be a start toward eliminating a generic "thank you."
Basically I think you're saying replace
mail($SendTo, $SubjectLine, $MsgBody, "From: " . $SendFrom); with
mail($SendFrom, $SubjectLine, $MsgBody, "From: " . $SendTo);
That doesn't do it. I know nothing about php - what in the code is saying where the email address is that the confirmation needs to send to?
Apologies for ignorance
You will need to look at the form you are using, find the name='' field where the person enters their e-mail address, the set a variable like $CCUser=$_POST['YourFormEMailFieldNameHere'];
mail($CCUser, $SubjectLine, $MsgBody, "From: " . $SendFrom);
Sorry I didn't notice before I posted the first time.
Here's what you're looking for:
<input type='text' name='YourFormEMailFieldNameHere'>
Put whatever YourFormEMailFieldNameHere is on your form between the quotes in the $_POST['YourFormEMailFieldNameHere'] on the PHP page... IOW the input field name for the e-mail and the $_POST[''] between the quotes need to match.
if (empty($_POST)) {
print "Error with form, please contact the webmaster.";
} else {
// Configuration Settings
$SendFrom = "Website Contact Form <info@blank.co.uk>";
$SendTo = "info@blank.co.uk";
$SubjectLine = " Web Site";
$ThanksURL = "thankyou.html"; //confirmation page
$Divider = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($REMOTE_ADDR) . "\n$Divider\n";
foreach ($_POST as $Field=>$Value)
$MsgBody .= "$Field: $Value\n";
$MsgBody .= $Divider . "\n" . $HTTP_USER_AGENT . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe
// Send E-Mail and Direct Browser to Confirmation Page
$CCUser = $_POST ["Email"];
mail($CCUser, $SendTo, $SubjectLine, $MsgBody, "From: " . $SendFrom);
header("Location: $ThanksURL");
}
?>
$SendFrom = "Website Contact Form <info@blank.co.uk>";
$SendTo = "info@blank.co.uk";
$SubjectLine = " Web Site";
$ThanksURL = "thankyou.html"; //confirmation page
$Divider = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($REMOTE_ADDR) . "\n$Divider\n";
foreach ($_POST as $Field=>$Value)
$MsgBody .= "$Field: $Value\n";
$MsgBody .= $Divider . "\n" . $HTTP_USER_AGENT . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe
// Send E-Mail and Direct Browser to Confirmation Page
$CCUser = $_POST ["Email"];
echo $CCUser;
exit;
If you don't see the e-mail address, something is wrong in setting the value or the form passing it, which generally the name in the POST array piece... I'd use single quotes and no space too, just to make sure there's no 'glitch' in there: $_POST['Email'];
If you want to see everything you're getting, change this line:
$MsgBody .= "$Field: $Value\n";
to
echo $MsgBody .= "$Field: $Value\n";
I also agree about just displaying a success message on the form page once it is submitted, that way you are reducing your exposure to sending backscatter and getting blacklisted in an RBL. If you are responding with the submitted contents you are leaving yourself open to those sorts of misuse.
Thanks for the help, but it's not working,
Sorry lol . . . yes you missed it. See my original post on page 1: what you want it two lines just like I posted.
mail (TO COMPANY, FROM SUBMITTOR);
mail (TO SUBMITTOR, FROM COMPANY);
That's really all there is to it. :-)
Here's the full code I would use:
<?
if (empty($_POST)) {
print "Error with form, please contact the webmaster.";
} else {
// Configuration Settings
$SendFrom = "Website Contact Form <info@blank.co.uk>";
$SendTo = "info@blank.co.uk";
$SubjectLine = " Web Site";
$ThanksURL = "thankyou.html"; //confirmation page
$Divider = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($REMOTE_ADDR) . "\n$Divider\n";
foreach ($_POST as $Field=>$Value) {
$MsgBody .= "$Field: $Value\n";
echo '<br>Field:'.$Field.' Value: .'$Value.'<br>';
}
$MsgBody .= $Divider . "\n" . $HTTP_USER_AGENT . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe
// Send E-Mail and Direct Browser to Confirmation Page
$CCUser = $_POST['Email'];
echo '<br><br>E-Mail Address Stored as $CCUser:'.$CCUser;
exit;
mail($CCUser, $SubjectLine, $MsgBody, "From: " . $SendFrom);
header("Location: $ThanksURL");
}
?>
You should see a white screen with plain text on it.
If the line that says E-Mail Address Stored as $CCUser: is blank after the : then there is something wrong with the variable. If not then there is something wrong with your mail() send function.
<?
if (empty($_POST)) {
print "Error with form, please contact the webmaster.";
} else {
// Configuration Settings
$SendFrom = "Website Contact Form <info@blank.co.uk>";
$SendTo = "info@blank.co.uk";
$SubjectLine = " Web Site";
$ThanksURL = "thankyou.html"; //confirmation page
$Divider = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($REMOTE_ADDR) . "\n$Divider\n";
foreach ($_POST as $Field=>$Value) {
$MsgBody .= "$Field: $Value\n";
}
$MsgBody .= $Divider . "\n" . $HTTP_USER_AGENT . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe
// Send E-Mail and Direct Browser to Confirmation Page
$CCUser = $_POST['Email'];
// echo '<br><br>E-Mail Address Stored as $CCUser:'.$CCUser;
mail($CCUser, $SubjectLine, $MsgBody, "From: " . $SendFrom);
mail($SendTo, $SubjectLine, $MsgBody, "From: " . $SendFrom);
header("Location: $ThanksURL");
}
?>
The error was a . and a ' in the wrong order in the line... I removed it too, because it was really just for troubleshooting.
I usually use an app that creates the code for the form and processor for me. In this case that's not appropriate.
Still can't get this thing to work though!
mail($CCUser, $SubjectLine, $MsgBody, "From: " . $SendFrom);
mail($SendTo, $SubjectLine, $MsgBody, "From: " . $SendFrom);
To this:
mail($SendTo.','.$CCUser, $SubjectLine, $MsgBody, "From: " . $SendFrom);
I don't see any reason why it wouldn't work the way it's written, so make sure you're using two distinct e-mail addresses, entering the e-mail address into the form correctly, and NOT getting caught in a spam filter on either of them.
The way it's written, if there's an error in the code the e-mail to the website will not be sent. You know you are getting an e-mail address posted to the form. You know the second mail is sending. The first mail() cannot have any type of critical error in it or the second mail would not be sent. The most likely conclusion I can draw is the mail() to the person completing the form (you in this case) is getting caught in the spam filter of the e-mail it's being sent to and is either in the spam box or being automatically discarded...
I'm just going to replace the word Email in the address it's showing in with "" (nothing), rather than trying to figure out why it's there and removing it the 'more correct' way.
<?
if (empty($_POST)) {
print "Error with form, please contact the webmaster.";
} else {
// Configuration Settings
$SendFrom = "Website Contact Form <info@blank.co.uk>";
$SendTo = "info@blank.co.uk";
$SubjectLine = " Web Site";
$ThanksURL = "thankyou.html"; //confirmation page
$Divider = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($REMOTE_ADDR) . "\n$Divider\n";
foreach ($_POST as $Field=>$Value) {
$MsgBody .= "$Field: $Value\n";
}
$MsgBody .= $Divider . "\n" . $HTTP_USER_AGENT . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe
// Send E-Mail and Direct Browser to Confirmation Page
$CCUser = $_POST['Email'];
// echo '<br><br>E-Mail Address Stored as $CCUser:'.$CCUser;
// Email below should be exactly (including case) what you would like to remove from the variable...
mail($SendTo.','.str_replace('Email','',$CCUser), $SubjectLine, $MsgBody, "From: " . $SendFrom);
header("Location: $ThanksURL");
}
?>
If it's still there for some reason, remove it from both:
mail(str_replace('Email','',$SendTo).','.str_replace('Email','',$CCUser), $SubjectLine, $MsgBody, "From: " . $SendFrom);
Like I said above, this is not the 'correct' way to fix the issue, and there are some members who will probably remind you of what I'm stating too, but IMO sometimes when you're talking about the value of time this far into a project a little 'get the job done' solution you can correct later is the best answer.