View Full Version : Contact Us Form php issue
davidjohny
04-04-2012, 01:05 PM
Hello
I have a website with an online subscription form in PHP.
Current status:
Step1/- A visitor fills in his name and email address.
Step 2/- Next, I get visitor name and email address inside my INBOX.
Step 3/- Next, I send an email to confirm his email address.
(Like...Just reply me back to confirm your email address etc...)
Current PHP form
==========================
[[[ Page with PHP Form Code ]]]
<form name="form" id="form" method="post" action="thankyou.php">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td><span class="style66">Name*</span></td>
<td><input name="name" type="text" id="name" /></td>
</tr>
<tr>
<td><span class="style66">E-mail*</span></td>
<td><input name="email" type="text" id="email" /></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<p> </p>
<p>
<input id="submit" type="image" src="images.png"value="submit"
name="submit" rntsubmit="true">
</p>
</div></td>
</tr>
</table>
</form>
===========================
===========================
[[[ Confirmation Page Code ]]]
<?php
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$body = "A user $name send data \n".
"Name: $name\n".
"Email: $email \n".
mail( "myemail@mydomainname.com", "User Data via Web Form", $body );
?>
===================================================
Question:
I want to automate the step 2 and step 3.
Like,.. I get visitor data inside my inbox but at the same time website visitor also gets an automatic email message from my side.
Best wishes,
Dave
======================
Please use the forum's bbcode tags and indent your code to make it more readable:
for php code............
<?php /* code goes here */ ?>
for html...............
<!-- markup goes here -->.....
for js/css/other.......
code goes here................
What you want will require a way to keep track of contact submissions, the email addresses that you've sent to, and the email address that have been confirmed (i.e., the replies you recieve). In other words, you'll need a database.
The process (logic) would go something like this:
# User submits form:
PHP validates the form submission
IF not valid PHP rejects it (show an error page, or something)
ELSE, PHP checks the database to see if the email address already exists
IF not, PHP:
-- saves the email address to the database
-- creates a unique confirmation code/link
-- sends the link to the user's email address
-- send the admin (you) a notification
# THEN, we wait for the user to click on the link in the email:
PHP checks the database to see if the confirmation code is valid
IF it is, PHP updates the database to show that the email was confirmed, and send the admin (you) a notification
ELSE, PHP rejects the confirmation (show an error page, or something)
links123
04-05-2012, 10:46 AM
function SendUserConfirmationEmail(&$formvars)
{
$mailer = new PHPMailer();
$mailer->CharSet = 'utf-8';
$mailer->AddAddress($formvars['email'],$formvars['name']);
$mailer->Subject = "Your registration with ".$this->sitename;
$mailer->From = $this->GetFromAddress();
$confirmcode = urlencode($this->MakeConfirmationMd5($formvars['email']));
$confirm_url = $this->GetAbsoluteURLFolder().'/confirmreg.php?code='.$confirmcode;
$mailer->Body ="Hello ".$formvars['name']."\r\n\r\n".
"Thanks for your registration with ".$this->sitename."\r\n".
"Please click the link below to confirm your registration.\r\n".
"$confirm_url\r\n".
"\r\n".
"Regards,\r\n".
"Webmaster\r\n".
$this->sitename;
if(!$mailer->Send())
{
$this->HandleError("Failed sending registration confirmation email.");
return false;
}
return true;
}
this will work
are you talking about PHPmailer (http://phpmailer.worxware.com)? A lot of the methods you're using don't seem to be on their methods list.
Aside from that, your example only addresses the "sending mail" part (and out of curiosity, why are you passing $formvars by reference?) - he needs to track the emails and follow up on confirmation replies as well.
davidjohny
04-05-2012, 04:37 PM
Current status:
Step 1/- A visitor fills in his email address.
Step 2/- Next, I get visitor email address inside my INBOX.
Step 3/- Next, I send him a following email message, manually.
=============Start Message==========
Subject: Verification required - Newsletter Subscription
Body:
Welcome to MY DOMAIN NAME.com
You, or someone using your email address, has applied
at http://mydomainname.com to receive our newsletter
"Just reply us back to confirm your email address"
If this is an error, ignore this email and you will be removed from our
mailing list.
Regards,
http://My Domain Name - Team
============= End Message==========
Current PHP form consist of two pages
===================================
[[[ Page with PHP Form Code | Page NO.1 Formpage.php ]]]
<html><body>
<form name="myform" method="post" action="SEND.php"><br> <br />
<input name="email" type="text" id="email" />
<br />
<input type="submit" name="Submit" value="Submit" />
</form>
</body></html>
==================================================
[[[ Confirmation Page Code | Page NO.2 SEND.php ]]]
<?php
$email = $_REQUEST['email'] ;
mail( "myemail@mydomain.com", "Newsletter Request", "From: $email" );
?>
===================================================
Question:
I want to automate the step 2 and step 3.
Like,.. I get visitor Email address inside my inbox but at the same time website visitor also gets an automatic email verification message from my side. I just want that visitor to reply me back to confirm his e-mail address.
What code I write to send an auto-email to $email?
Best wishes,
Dave
======================
mburt
04-05-2012, 07:24 PM
PHP has no way of checking to see if new mail is in an inbox- so your idea of automating this process (seems to be) impossible. I think the order in which you're thinking about this is wrong. It is possible, however, if you send a test e-mail to the person who's trying to set it up. Try it this way:
1) Visitor fills in e-mail address
2) A test e-mail is sent to HIS/HER address with a link in it. This link will go to a page that will change some DB value in accordance with that e-mail address to verify it
3) Once the link is clicked, the e-mail is verified, then you can add his/her e-mail to the subscribe list
This is how most sign-up forms work for anything. If you need specifics you can message me.
Did you read my post (post #2 above)?
I outlined a possible solution for automating the process. Do you currently have a database for your site? Do you have any experience writing PHP that interacts with a database?
If you have any questions about my suggestion, please, ask! I'll be happy to help you figure it out.
If you are looking for someone to just write the code for you, you should post in the paid help forum (http://www.dynamicdrive.com/forums/forumdisplay.php?f=30).
@mburt
Actually, PHP can check email boxes, but its complicated and not really necessary for this sort of task.
The approach you outlined is preferable (very close to what I described as well).
@mburt
Sorry: only the "edit" portion of this post was directed at your reply.
My "did you read" question was directed at the OP.
mburt
04-05-2012, 07:39 PM
@traq Yeah I read through your post, but I wanted to re-iterate the facts and simplify the process. (I do realize that essentially we are suggesting the same thing).
davidjohny
04-05-2012, 09:38 PM
Hi
I did a little search about headers and my problem has solved.
My PHP script is working fine. Thanks to good forum and quick members.
Now, there is another issue. It is about security!
I have heard that spammers use php code injection, malicious script and do spamming.
How can I secure this simple two pages php form?
Best wishes,
Dave
=============
Current PHP form consist of two pages
=================================================
[[[ Page with PHP Form Code | Page NO.1 Formpage.php ]]]
<html><body>
<form name="myform" method="post" action="SEND.php"><br> <br />
<input name="email" type="text" id="email" />
<br />
<input type="submit" name="Submit" value="Submit" />
</form>
</body></html>
=================================================
[[[ Confirmation Page Code | Page NO.2 SEND.php ]]]
<?php
$email = $_REQUEST['email'] ;
mail( "myemail@MyDomainName.com", "Newsletter Request", "From: $email" );
?>
<?php
$subject="Verification required - Newsletter Subscription";
$body ="
Welcome to MY DOMAIN NAME.com
You, or someone using your email address, has applied
at http://mydomainname.com to receive our newsletter
Just reply us back to confirm your email address
If this is an error, ignore this email and you will be removed from our
mailing list.
Regards,
http://My Domain Name - Team
";
$headers = 'From: myemail@MyDomainName.com' . "\r\n" .
'Reply-To: myemail@MyDomainName.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail( $email, $subject, $body, $headers );
?>
=================================================
mburt
04-07-2012, 04:04 AM
Simple just use:
$_POST["email"]
not
$_REQUEST["email"]
That way there is no chance of the get variable getting injected into the code. Other than that it looks pretty secure.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.