|
Posted by ianbarton on 09/26/06 10:42
I finally got this all sorted out and it works fine. I have even gone
one step more and generate 2 emails, one to myself and another back to
the person who sent the feedback, providing they provide a valid email
address. This second part isn't necessary but I was "on a roll" so kept
going.
Here is my "contact.php" script. Remember that it has to be mentioned
in the Feedback form with a line
<form method="post" action="contact.php">
Thanks to all those who offered some assistance.
Ian
<?php
// Website Contact Form Generator
// get posted data into local variables ready for email to Ian
$EmailFrom = Trim(stripslashes($_POST['UserEmail']));
$Country = Trim(stripslashes($_POST['UserCountry']));
$EmailTo = "my own email address";
$Subject = "Web Site Feedback";
$Name = Trim(stripslashes($_POST['UserName']));
$Comments = Trim(stripslashes($_POST['Comments']));
// validation
// not used as my Form has it's own validation
//$validationOK=true;
//if (Trim($EmailFrom)=="") $validationOK=false;
//if (Trim($Country)=="") $validationOK=false;
//if (Trim($Name)=="") $validationOK=false;
// if (Trim($Telephone)=="") $validationOK=false;
// if (Trim($Email)=="") $validationOK=false;
//if (Trim($Comments)=="") $validationOK=false;
//if (!$validationOK) {
// print "<meta http-equiv=\"refresh\" content=\"0;URL=index.htm\">";
// exit;
//}
// prepare email body text to Ian
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Country: ";
$Body .= $Country;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "\n";
// send email to Ian
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// get posted data into local variables ready for email to User
$EmailFrom = "";
$EmailTo = Trim(stripslashes($_POST['UserEmail']));
$Subject = "Web Site Feedback Comments";
$Comments = Trim(stripslashes($_POST['Comments']));
// prepare email body text to User
$Body = "";
$Body .= "Hello ";
$Body .= $Name;
$Body .= "\n";
$Body .= "\n";
$Body .= "Here is a copy of the Comments you sent to Ian's Website";
$Body .= "\n";
$Body .= "\n";
$Body .= "Comments: ";
$Body .= "\n";
$Body .= $Comments;
$Body .= "\n";
// send email to User
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=confirm.htm\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
Colin Fine wrote:
> ianbarton@adam.com.au wrote:
> > Thanks Erwin for your reply.
> >
> > I know nothing about PHP but since I started this exercise I have
> > become a little, just a little more familiar with this particular
> > function. Unfortunately I wouldn't know enuff to know whether it is
> > good or bad code so I will have to take your word for that.
> >
> > In your reply you state "No, you want to put there the from address.
> > Since this script automatically sends the email, you'll have to tell it
> > what the from-field is. Most probably you can put in there any valid
> > emailaddress you own, like: info@adam.com"
> >
> > The email address that I want to put in there is that which is supplied
> > in the feedback form field I have titled "UserEmail" The trouble is I
> > don't know what the syntax is to do this. I have tried many variations
> > (eg)
> >
> > $header .= "From: Web Form <UserEmail>\n";
> > $header .= "From: <UserEmail>\n";
> > $header .= "From: 'UserEmai'l>\n";
> > $header .= "From: <$UserEmail>\n";
> > $header .= "From: $UserEmail\n";
> >
> > Am I trying to do something that just isn't possible in PHP. I have
> > done this in ASP on another webpage but I can't get it to work here.
> >
> Probably
>
> $_REQUEST['UserEmail']
>
> (or $_GET or $_POST instead of $_REQUEST if you know which HTTP method
> is being used. But $_REQUEST will do for either.)
>
> Colin
Navigation:
[Reply to this message]
|