Forum Moderators: coopster
In the form I simply have "message" box and an "email" box.
<?php
// ************Begin Configure***************
//Put where you want the email to go
$mailto = "name@mydomain.com";
//Put your subject in here
$subject = "Question from website";
//Put where to redirect to after sending the email
$redirect = "thankyou.htm";
// ************End Configure****************
foreach($HTTP_POST_VARS as $key => $value) {
$message .= $key . '<BR> ' . $value;
$msg .= "Message: $message\n<BR>";
}
if (@mail($mailto, $subject, $message)) {
header("Location: $redirect");
} else {
// This echo's the error message if the email did not send.
// You could change the text in between the <p> tags.
echo('<p>Mail could not be sent. Please use your back button to try again.</p>');
}
?>
[edited by: Selander at 6:18 pm (utc) on May 27, 2003]
dmorison was referring to this
if (@mail($mailto, $subject, $message)) {
take a look at the php mail() function [php.net] on php.net. It gives you a good breakdown of how to setup the proper headers for the email.
Try this out:
<?php
// ************Begin Configure***************
//Put where you want the email to go
$mailto = "name@mydomain.com";
//Put your subject in here
$subject = "Question from website";
//Put where to redirect to after sending the email
$redirect = "thankyou.htm";
//Put the address you want it sending FROM
$from = "From: you@yourdomain.com";// ************End Configure****************
foreach($HTTP_POST_VARS as $key => $value) {
$message .= $key . '<BR> ' . $value;
$msg .= "Message: $message\n<BR>";}
if (@mail($mailto, $subject, $message, $from)) {header("Location: $redirect");
} else {
// This echo's the error message if the email did not send.
// You could change the text in between the <p> tags.
echo('<p>Mail could not be sent. Please use your back button to try again.</p>');
}
?>
Let us know.
wruk999
This was because of the variable set in the config section of your script I posted:
//Put the address you want it sending FROM
$from = "From: you@yourdomain.com";
>> Just by chance I added.. $from = "From: <$email>";
This is because you have this line in:
foreach($HTTP_POST_VARS as $key => $value) {
so when Jatar said put this in: $from = "From: $HTTP_POST_VARS['email']";
it already had set $email equal to $HTTP_POST_VARS['email']
Hope this clears it up ;)
wruk999
The email response from the form is pretty basic, which is fine but is there a way to include a carrage return after each text box response in the email? For examlpe this is was I receive currently....
CompanyName<BR> businessAddress<BR> 2434Attn<BR> janCity<BR> morrisonPhone<BR> 555-1234State<BR> ILSubmit
Is there anyway for the email response to look like this....
CompanyName: business
Address: 2434
Attn: jan
City: morrison
Phone: 555-1234
State: IL
The from var that we were talking about before is a bit of a misnomer. It should really be called $headers because it is the var in the function where you pass extra headers.
this is the function
bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]])
this would allow you to put html in the message.
$headers = "From: $HTTP_POST_VARS['email']\r\nContent-type: text/html\r\n";
mail($mailto, $subject, $message, $headers)
or you could use \r\n after every line instead of <br> for text only messages.
foreach($HTTP_POST_VARS as $key => $value) {$message .= $key . '<BR> ' . $value;
$msg .= "Message: $message\n<BR>";}
with
$message = "";foreach($HTTP_POST_VARS as $key => $value)
{
$message .= $key . ":" . $value . "\n";
}
This should certainly create a plain text email with the content you want...