PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Help with gmail form

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PEAR Forum Forum Index -> General PEAR questions
View previous topic :: View next topic  
Author Message
steve



Joined: 02 Apr 2008
Posts: 3

PostPosted: Mon Apr 07, 2008 2:58 am    Post subject: Help with gmail form Reply with quote

Confused 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 [email protected] to [email protected], 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 = "[email protected]";
$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 = "[email protected]";
$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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1235

PostPosted: Mon Apr 07, 2008 5:51 pm    Post subject: Reply with quote

What exactly is your question? Can't you just use the $visitor variable for the 'From' header of the generated email?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PEAR Forum Forum Index -> General PEAR questions All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
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



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement