PHP Email List Subscriber Script [duplicate] - php

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 7 years ago.
Why won't this script work? I just want an email sent to hello#weblabcompany.com with the email of the subscriber so I can follow up with them later
<div class="col-2" id="sub-box">
<h1 class="text-white margin-bottom"> Subscribe to Web Lab </h1>
<h2 class="text-white margin-bottom"> Receive articles as they are published </h2>
<form name="subscribe" action="/submail.php" method="post"> <input type="email" value="Email"> <input type="submit" value="Send" class="width-25"> </form>
</div>
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "hello#weblabcompany.com";
$email_subject = "New Sub";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
!isset($_POST['email'])
{
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$email = $_POST['email']; // required
//$error_message = "";
//$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
//if(!preg_match($email_exp,$email_from)) {
//$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
//}
//$string_exp = "/^[A-Za-z .'-]+$/";
//if(!preg_match($string_exp,$name)) {
//$error_message .= 'The First Name you entered does not appear to be valid.<br />';
//}
//if(!preg_match($string_exp,$email)) {
//$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
//}
//if(strlen($message) < 2) {
//$error_message .= 'The Comments you entered do not appear to be valid.<br />';
//}
//if(strlen($error_message) > 0) {
//died($error_message);
//}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "email: ".clean_string($email)."\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>

You don't have the input's name attribute set to email.

Related

How to pass checkbox selections to php mailer form?

The checkbox fields are not passing to my email from my html form.
When a user fills in the form all the information is received in my email (user name, email, phone, comments) except for the boxes they checked on the form.
I have tried putting the [] like this name="feature[]" in the name field but did not work so I reverted back.
My form....
<form name='quote' method="post" action="quote-request.php">
...
<center><h4 style='color:#C42D35'>Check each feature you will need:</h4></center>
<div class='row'>
<div class='col-md-6'>
<input type="checkbox" name="feature" value="something" checked> Basic <br>
<input type="checkbox" name="feature" value="something1"> Option 1 <br>
<input type="checkbox" name="feature" value="something2"> Option 2 <br>
</div>
<div class='col-md-6'>
<input type="checkbox" name="feature" value="something3"> Option 3 <br>
<input type="checkbox" name="feature" value="something4"> Option 4 <br>
</div>
</div>
...
</form>
My handler (quote-request.php)...
<?php
if(isset($_POST['email'])) {
$email_to = "myemail#mydomain.com";
$email_subject = "Quote Request";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['firstName']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['feature']) ||
!isset($_POST['comment'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$firstName = $_POST['firstName']; // required
$email_from = $_POST['email']; // required
$phone = $_POST['phone']; // not required
$feature = $_POST['feature']; // required
$comment = $_POST['comment']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$firstName)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($comment) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($firstName)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($phone)."\n";
$email_message .= "Comments: ".clean_string($comment)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>

Can't find error PHP

So, this is my first attempt in PHP so it might be very easy to fix. I am trying to make a form which can be submitted and sent to administration's e-mail.
I am running a server with MAMP, going online filling the form, submitting it and I get error:
We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.
We are sorry, but there appears to be a problem with the form you submitted.
Please go back and fix these errors.
Full PHP code:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "I HAVE CORRECT EMAIL HERE 4 SURE";
$email_subject = "eShop Contact Form";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['fname']) ||
!isset($_POST['lname']) ||
!isset($_POST['email']) ||
!isset($_POST['subject'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['fname']; // required
$last_name = $_POST['lname']; // required
$email_from = $_POST['email']; // required
//$country = $_POST['country']; // not required
$comments = $_POST['subject']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
// $email_message .= "Country: ".clean_string($country)."\n";
$email_message .= "Subject: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
This is the part that should be having problem:
// validation expected data exists
if(!isset($_POST['fname']) ||
!isset($_POST['lname']) ||
!isset($_POST['email']) ||
!isset($_POST['subject'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
P.S I have copied the code from http://www.freecontactform.com/email_form.php here and edited it a little.
Well, now I will start from here.
I will re-edit your code
SUBMIT.PHP
<?php
if(isset($_POST['formid'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "yourmail.com.id#maisetting.com";
$email_subject = "eShop Contact Form";
//
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['email'];
$subject = $_POST['subject'];
$comments = $_POST['comm'];
// I was replace this line
// validation expected data exists
if(empty($fname) or empty($lname) or empty($mail) or empty($subject) or empty($comments)){
$err_msg = 'We are sorry, but there appears to be a problem with the form you submitted.';
} else {
// check mail registered
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$mail)) {
$err_msg = 'The Email Address you entered does not appear to be valid.<br />';
} else {
// check name
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$fname)) {
$err_msg = 'The First Name you entered does not appear to be valid.<br />';
} else {
// check Last name
if(!preg_match($string_exp,$lname)) {
$err_msg = 'The Last Name you entered does not appear to be valid.<br />';
} else {
// Check comment
if($comments<2 or $comments=='') {
$err_msg = 'The Comments you entered do not appear to be valid.<br />';
} else {
// SEND msg from the visitor
$err_msg = 'Your Messages Was Send. ThankYou!';
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($fname)."\n";
$email_message .= "Last Name: ".clean_string($lname)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
// $email_message .= "Country: ".clean_string($country)."\n";
$email_message .= "Subject: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
}}}}} } else { $err_msg = 'Add Your comment here'; }
?>
INDEX.PHP
<?php require('SUBMIT.PHP'); ?>
<form action="#" method="post" />
<p><label>First Name</label>
<input type="text" placeholder="First name here" name="fname" />
</p>
<p><label>Last Name</label>
<input type="text" placeholder="Last name here" name="lname" />
</p>
<p><label>Mail</label>
<input type="text" placeholder="Add yourmail here" name="mail" />
</p>
<p><label>Subject</label>
<input type="text" placeholder="Subject here" name="subject" />
</p>
<p><label>Your Comment</label>
<textarea name="comm"></textarea>
</p>
<p><input type="submit" name="formid" value="Send" /></p>
</form>
<?php echo $err_msg; ?>
Now, do and test.

Sending an html form email with PHP [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 5 years ago.
When I click my submit button, It pulls up my form-to-email.php source code. This is my first time using any PHP. How do i get it to send the email? It could just be linked incorrectly or formatted incorrectly.
<form method="post" name="myemailform" action="form-to-email.php">
<div>
<label for="name">Name:</label><br>
<input type="text" id="name" name="user_name" size="45"><br>
</div>
<div>
<label for="email">Email:</label><br>
<input type="text" id="email" name="user_email" size="45"><br>
</div>
<div>
<label for="message">Message:</label><br>
<textarea type="text" id="message" name="user_message" size="600"></textarea><br>
</div>
<div>
<input type = "submit" value = "Send Form">
<input type = "reset" value = "reset">
</div>
</form>
here is my PHP code
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "codymaheu#yahoo.com";
$email_subject = "Testing";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['user_name']) ||
!isset($_POST['user_email']) ||
!isset($_POST['user_message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['user_name']; // required
$email_from = $_POST['user_email']; // required
$comments = $_POST['user_message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Message you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Message: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
add name into the button like this then try again
<input type = "submit" value = "Send Form" name="email">

PHP Form not redirecting with Header- Won't redirect [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
Used this form template to create a form, and took out a few fields as they were not all necessary.
http://www.freecontactform.com/html_form.php
However, my header command is not redirecting my page. Here's the code. Please note that I have tried with and without exit at the end.
The problems isn't that it won't send out an email, but won't redirect.
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "emailt#yahoo.com";
$email_subject = "Email from email.com";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['email']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_comments .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
header("Location: http://www.website.com/contactSoon.html");
}
?>
Here is the contact form I'm using-
<form name="htmlform" method="post" action="html_form_send.php">
<div class="row form-group">
<div class="col-md-12">
<label for="first_name">Name *</label>
<input type="text" name="first_name" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label for="comments">Email Address *</label>
<input type="text" id="email" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label for="message">Message *</label>
<textarea name="message" id="message" cols="30" rows="10" class="form-control"></textarea>
</div>
</div>
<div class="g-recaptcha" data-sitekey="6LfmXB4UAAAAAHxguDJIQXClAG_8rGe6qnK1SldM"></div>
<div class="form-group">
<input type="submit" name="submit" id="submit" value="Send Message" class="btn btn-primary">
</div>
</form>
Change to
<?php
//memory increase max
ini_set('memory_limit', '-1');
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "emailt#yahoo.com";
$email_subject = "Email from email.com";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['email']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_comments .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
echo '<script>window.location.href = "http://www.website.com/contactSoon.html";</script>';
//header("Location: http://www.website.com/contactSoon.html");
}
?>
So it's going to redirect with javascript insted of php

How can I change the location of my error, messages?

How do I redirect the error messages from my html_form_send.php back to my registration.php page. Here is what I got, I have my registration.php with the following code:
registration.php (location : /root/ )
<!-- register -->
<div>";
include "$template/email.php";
echo "
</div>
<!-- register -->
My email.php links to my html_form_send.php which has the following code:
email.php (location : /root/models/template )
<form name='htmlform' action='$template/html_form_send.php' method='post' class='form-horizontal well' >
<fieldset>
<legend>Register for an account</legend>
<!-- placeholder for errors -->
<!-- placeholder for errors -->
<br>
<div class='control-group'>
<div class='control-label'>
<label>Name</label>
</div>
<div class='controls'>
<input type='text' placeholder='Type name' name='name' class='input-large'>
My html_form_send.php has the following code for an email client that I am using. I want to show the errors on my registration page.
registration.php (location : /root/models/template )
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "danielobo2#yahoo.com";
$email_subject = "Registering to blanky-store.net web design account.";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted.";
echo "These errors appear below. <a href='../../../register.php'>Return to previous page</a><br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors. <a href='../../../register.php'>Return to previous page</a><br /><br />";
echo "<a href='../../../register.php'>Return to previous page</a><br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['password'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$password = $_POST['password']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($telephone) < 2) {
$error_message .= 'The Telephone you entered do not appear to be valid.<br />';
}
if(strlen($password) < 2) {
$error_message .= 'The Password you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Password: ".clean_string($password)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
if (mail($email_to, $email_subject, $email_message, $headers)) {
header("Location: http://blanky-store.net/index.php");
}
?>
<?php
}
die();
?>
What I want to do is display the error messages that are appearing on the html_form_send.php and send them to my registration.php instead of displaying on my html_form_send.php page. I have an example of what is doing at this following page http://blanky-store.net/access/register.php
also what would be the code to combine the email.php page and the html_form_send.php form into one php page?
Store the error message in a session and then redirect the page to registration.php
Hence check for the session if is set or not. if error message is set then display the session value and after that unset the session value..
Hope it helps..

Categories