 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
steve
Joined: 02 Apr 2008 Posts: 3
|
Posted: Mon Apr 07, 2008 2:58 am Post subject: Help with gmail form |
|
|
Hi forum users,
I'm kinda new to this php stuff and would like a little help with a web form.
I have setup a web form through gmail smtp but when i fill out the form it mails it to my test address from my gmail account, but doesn't include the visitors email address. I receive an email from my@gmail to my@test, even if i use another email address, so i have no idea who the email is from.
I have not added the $visitor to the create and send as I'm not sure where it should be placed or even if i have placed it correctly in the php form data.
Can anyone be of assistance?
php script
<?php
require_once "Mail.php";
//Store form data in local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "My@TestAccount.com";
$Visitor = Trim(stripslashes($_POST['Visitor']));
$Subject = Trim(stripslashes($_POST['Subject']));
$Message = Trim(stripslashes($_POST['Message']));
// Require fields
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
exit;
}
$validationOK=true;
if (Trim($Subject)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
exit;
}
$validationOK=true;
if (Trim($Message)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
//smtp variables
$host = "smtp.gmail.com";
$port = "587";
$username = "My@gmail.com";
$password = "xxxxxxx";
//reCaptcha validation
require_once('recaptchalib.php');
$privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=captcha.html\">";
exit;
}
//create and send
$headers = array ('From' => $EmailFrom,
'To' => $EmailTo,
'Subject' => "Web contact - $Subject");
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'port' => $port,
'username' => $username,
'password' => $password));
$mail = $smtp->send($EmailTo, $headers, $Message);
//show form submission result
if (PEAR::isError($mail)) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
exit;
} else {
print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.html\">";
}
?>
Form
<center><form method="POST" action="contact.php">
Fields marked (*) are required.
<p>Name: *<br>
<input type="text" name="Visitor"></p>
<p>Email Address: *<br>
<input type="text" name="EmailFrom"></p>
<p>Subject: <br>
<input type="text" name="Subject"></p>
<p>Message: *<br>
<textarea name="Message" rows="15" cols="40"></textarea>
<p><script type="text/javascript"
src="http://api.recaptcha.net/challenge?k=xxxxxxxxxxxxxxxxxxxxxxx">
</script><br>
<noscript>
<iframe src="http://api.recaptcha.net/noscript?k=6xxxxxxxxxxxxxxxxxxxx"
height="300" width="500" frameborder="2"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40">
</textarea>
<input type="hidden" name="recaptcha_response_field"
value="manual_challenge">
</noscript>
<p><input type="submit" name="submit" value="Submit"></p>
</form></center> |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1048
|
Posted: Mon Apr 07, 2008 5:51 pm Post subject: |
|
|
| What exactly is your question? Can't you just use the $visitor variable for the 'From' header of the generated email? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|