Help With Notify Me Form - php

I'm trying to make a simple form like this http://birdboxx.com/, where the user can enter their email address to be notified when our site has launched.
I've looked at the HTML their using and it all looks pretty simple, I'm just not sure on how to code the PHP part. Could someone maybe help me out?
Thanks in advance.

The form in the given example (the relevant parts):
<form name="form-email-submit" id="form-email-submit" action="add_email.php" method="POST">
<input type="text" id="input-email" name="input-email" value="Enter your email here"/>
<input type="submit" title="Notify Me" value="Notify Me">
</form>
In your PHP script:
//In the add_email.php
$notificationEmail = $_POST['input-email']; // from the name="input-email" in the form
So now you have the email submitted, you can do whatever you want with it. You can write it to a file, or save it to a database, or whatever.

Basic solution for the email saving part.
The HTML:
<form method="post" action="">
<input type="email" name="email" placeholder="Enter your email here" /> <input type="submit" name="send" value="Notify me" />
</form>
The PHP with MySQL for saving:
$dbhost = "your host";
$dbuser = "your username";
$dbpass = "your password";
$dbname = "database name";
$c = #mysql_pconnect($dbhost,$dbuser,$dbpass) or die();
#mysql_select_db($dbname,$c) or die();
//It isn't secure in this state: validation needed as it is an email?
if(isset($_POST['send'])){
$email = mysql_real_escape_string($_POST['email']);
mysql_query('INSERT INTO email (id,email) VALUES (NULL,'.$email.');');
}
For sending emails I recommend phpmailer or any other solution: http://phpmailer.worxware.com/

Related

PHPMailer send mail with array ( $_POST['email'] )

Hi I have question about HTML and PHP array form. In the HTML form I ask 3 emails and send them to my database.
Someone knows how to make it work please? Thanks!
HTML FORM:
<form id="formulario" method="post" action="php/enviar.php" enctype="multipart/form-data">
<input type="email" name="email" required>
<input type="email" name="email1" required>
<input id="submit" type="submit" name="enviar" value="Send mail">
</form>
PHPMailer Part:
$para1 = $_POST['email'];
$para2 = $_POST['email1'];
$recipientes = array('joglym#gmail.com', 'jorgeloaiza12#gmail.com');
foreach($recipientes as $email)
{
$mail->AddAddress($email);
print_r($email); //only test
}
Error:
Invalid address: emailemail
Invalid address: email1email1
You must provide at least one recipient email address.
Thanks, sorry for my bad english!
First of all,I do not think you have implemented the PHPMailer the rght way.
Take a look at the PHPMailer github link for the simple example on how it is implemented.
1) You have to first include the PHPMailer class in your code
2) Then initialize the PHPMailer like $mail = new PHPMailer;. Have to set all the properties of the initialized object and then send mail.
You have mentioned about sending the datas to database although you have not provided any code of what you are trying to do

Password protected form with HTML and PHP

I'm making a html form and need people to validate that they are who they say they are. How I'm planning on doing this is with a password field. From which the password will be sent to them by email. So only one password is eneugh, so no need for dozens of different passwords.
The HTML
<form action="contact.php" method="post">
<!--entire form here-->
<input type="password" name="pwd" placeholder="Password" required />
<input type="submit" value="submit" id="button"/>
</form>
So my question is:
How do I select what the password is (I think in contact.php, not sure)
How do I process the password in contact.php
Thanks in advance!
Your form sends data to the page contact.php
Here's what to write in contact.php so you'll get the value from the input:
<?php
if (isset($_POST['pwd']))
{
//comparing the user input with the good password
if ($_POST['pwd'] == 'THE_GOOD_PASSWORD_GOES_HERE')
{
echo 'Password is good';
}
else
{
echo 'Wrong password';
}
}
?>
Replace THE_GOOD_PASSWORD_GOES_HERE with your password.
Also, please consider reading this

Not set when I first open page

I'm still new and trying to learn php. I have a form and everytime I run it I get an error displaying that the variable were not set when they should be. I'm definately missing something. Kindly explain what why is the variable $_POST['login_button'] not set the first time i run the page?
Code can be found below:
<?php
require 'connect.inc.php';
if (isset($_POST['login_button']) && isset($_POST['username']) && isset($_POST['password'])){
$login_button = $_POST['login_button'];
$username = $_POST['username'] ;
$password = $_POST['password'];
$password_hash = md5($_POST['password']);
if(!empty($username)&&!empty($password)){
$sql = "SELECT `id` FROM `golden_acres_username` WHERE `uname`='$username' AND '".$password_hash."'";
if($sql_run = mysql_query($sql)){
$query_num_rows = mysql_num_rows($sql_run);
}
if($query_num_rows==0){
echo'User name and password are incorrect';
}
else if($query_num_rows==1)
{
echo 'Username and password are correct';
}
}
else
{
echo 'Please fill in user name and password';
}
}
else
{
echo'Fields are not set';
}
?>
<form class="home_logon_area" action="test.php" method="POST">
Username:
<input type="text" name="username" />
Password:
<input type="password" type="password" name="password"/>
<input type="submit" name="login_button">
</form>
Thanks in advance,
Joseph
$_POST contains the result of submitting a form. If no form has been submitted yet, it will not contain anything.
Your script is working just fine; remove echo 'Fields are not set';, or use that line for code that should only run when the form hasn't been submitted yet.
The $_POST variable is set by the server to capture the data content sent by the browser as part of the form POST action. When the page is initially loaded, the browser has only executed/requested a GET call for the content of the page without sending the POST request.
Hope that helps!
This is simple to understand ;-)
First time the phpscript is executed to get the Form
So there will be no information at all (the visitor is new and have not seen the form before)
Then the User fills the form and press Submit button
The form is linked to the same side so the same phpscript gets executed again
Now you have the Formular values transmitted and you can acess them over $_POST
For more information look at php.net
Remove last else from your code and update the form with this one
<form class="home_logon_area" action="test.php" method="POST">
Username:
<input type="text" name="username" required />
Password:
<input type="password" type="password" name="password" required/>
<input type="submit" name="login_button">
</form>

PHP form that shows secret page when user submits name & email

I'm basically trying to create a form that collects a users name, email and company, mails that information to me, and then opens up a secret page to them. I think I'm on the right track, hoping you guys can help me out.
Form:
<form id="form1" action="submit.php" method="post">
<label for="name-id" >Full Name</label>
<input id="name-id" name="name-id" type="text"/>
<label for="email-id" >Email</label>
<input id="email-id" name="email-id" type="text"/>
<label for="company-id" >Company Name</label>
<input id="company-id" name="company-id" type="text"/>
<input type="submit"/>
</form>
PHP:
<?php
$name = $_POST["name-id"];
$email = $_POST["email-id"];
$company = $_POST["company-id"];
if($name != null && $company != null && filter_var($email, FILTER_VALIDATE_EMAIL){
echo "all forms filled";
mail("me#me.com", "subject - success", "body - someone passed");
include ("secretpage.php");
exit();
} else {
include ("homepage.php");
} ?>
Max,
You should redirect your customer to secretpage or homepage instead of include files in a same page.
You can do it by using javascript, window.location="secretpage.php" or window.location="homepage.php" depends upon an authentication.
If your code is not working remove "filter_var($email, FILTER_VALIDATE_EMAIL)" from your if condition. write error_reporting(E_ALL) and ini_set("display_errors",1) at the top of your page code, which will help to track an error.

PHP Script won't recognise email [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm getting pretty far with my registration script now. This has been such an amazing learning curve for me. As of now I've just finished up some bugs with my user recognition and registration email send outs. I'm having some issues with recovering a password though. At the moment I am just trying to get an email recognised, here is my HTML and PHP:
HTML
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php include "header.php" ?>
<div id="wrapper">
<form method="post" action="">
<h2>Recover Password</h2>
<div id="underline"></div>
<ul>
<li>
<label for="usn">Email : </label>
<input type="text" maxlength="30" required autofocus name="reset" />
</li>
<li class="buttons">
<input type="submit" name="reset" value="Reset Pass" class="xbutton" />
</li>
</ul>
</form>
</div>
</body>
</html>
<?php include "prec.php" ?>
PHP
<?php
if($_POST)
{
if(empty($_POST['reset']))
{
echo 'Please enter all fields';
}
else
{
$email = $_POST['reset'];
$password = $_POST['password'];
$db_name =
$db_user =
$db_pass =
$conn = new PDO('mysql:host=localhost;dbname=tweezy_php', 'tweezy_php', 'XXXXXX',
array( PDO::ATTR_PERSISTENT => true ));
$stmt = $conn->prepare("SELECT email FROM users WHERE email = ? ");
$stmt->execute(array($email));
if($stmt->rowCount() === 1 )
{
echo "That email exists";
}
else
{
echo "Sorry, that email doesn't exsist.";
}
}
}
?>
For some reason, no matter what I enter the supplied email is never recognised. Looking through my code I don't quite see why though. I've tried a couple of variations, but it just seems to give me the same result. I'm thinking it has something to do with my SQL query, but I can't seem to quite put my finger on it.
Any insights would be wonderful!
Your input field is:
<input type="text" maxlength="30" required autofocus name="reset" />
Change this to:
<input type="text" maxlength="30" required autofocus name="email" />
And, in your PHP, you'd do something like this to retrieve the email from the user:
$email = $_POST['email'];
A simple example to demonstrate why it's failing:
test.php
<?php
if(isset($_POST['fieldname'])){
echo $_POST['fieldname']; //outputs "Submit" instead of the user input
}
?>
<form action="" method="post">
<input type="text" name="fieldname"/>
<input type="submit" name="fieldname">
</form>
Both the input field and submit button has the same name. So when you input something and click on submit, you will find that instead of echoing the user input, it echoes the text Submit. This is because the first input is being overridden by the name attribute in your Submit button. This can be resolved by changing your email input's name attribute to something different, like email so it makes more sense.
Hope this helps!
You have two fields in the form that contain name="reset". One is the email field, the other is the submit button.
This will confuse things -- only one of those values will get into your $_POST array, and it looks like it's the wrong one.
You should tidy up the form and ensure that your field name attributes do not clash.
In addition, I note that the email field has a label near it that has for="usn", but there isn't a usn field anywhere to be seen. That won't cause any problems, but is badly incorrect (it looks like a copy+paste bug) -- you probably fix that too.
Change $email to This:
$email = $_POST['username'];
And
if(!isset($_POST['reset']))
Try the following:
$conn = new PDO('mysql:host=localhost;dbname=tweezy_php', 'tweezy_php', 'XXXXXX',
array( PDO::ATTR_PERSISTENT => true ));
$stmt = $conn->prepare("SELECT email FROM users WHERE email = ? ");
$stmt->bindValue(1, $email);
$stmt->execute();
$result = $stmt->fetchAll();
if(count($result) === 1 ){
echo "That email exists";
}else{
echo "Sorry, that email doesn't exsist.";
}
Also, you should change the name of the email's input. It is conflicting with another input and if two inputs have the same name without them being an array, the last input's value will be presented to the server.
That should resolve the issue. Hope this helps.
Your issue is because you're checking the Reset button for a value and not the email field. Here's your email field:
<input type="text" maxlength="30" required autofocus name="username" />
So you need to change this:
if(empty($_POST['reset']))
AND
$email = $_POST['reset'];
To check $_POST['username'] instead.
Both your reset and email input fields are named reset (name="reset"). This will result in the first field (which should be named email) being overriden by your actual reset input field
Change your email input to
<input type="text" maxlength="30" required autofocus name="email" />
And your $email to
$email = $_POST['email'];

Categories