Website source: http://www.salefee.com/
Can someone checkout my above mentioned site..I have made a form under "To recieve the salefee story ebook,submit your email id"
I have made a form in which user submits his email id,then form is linked to a php file which sends email to user email id. THE PROBLEM IS THAT FORM IS NOT BIENG REDIRECTED TO .php FILE. I have added action
and method
attribute in HTML form. The php code is not being executed when user clicks submit button.
The code of HTML is as follows:
<!-- Mailchimp Newsletter -->
<div style="text-align:center">
<div class="newsletter-wrapper animateblock rtl-2 speed-1">
<form action="story.php" method="post" class="form-inline subscription-mailchimp">
<div class="form-group input-group input-newsletter">
<input class="form-control" id="newsletter-email" name="newsletter-email" type="email" placeholder="Enter email">
<div class="input-group-btn">
<button class="btn btn-danger" type="submit">Sign Up</button>
</div>
</div>
</form>
<small class="help-block">Don't worry. We do not spam :)</small>
</div>
</div>
<!-- End Mailchimp Newsletter -->
My php code named as story.php is as follows:
<?php
if ($_POST) {
$to_email = "salefee12@gmail.com" //Recipient email, Replace with own email here
//Sanitize input data using PHP filter_var().
$user_trial_email = filter_var($_POST["newsletter-email"], FILTER_SANITIZE_EMAIL);
//additional php validation
if (!filter_var($user_trial_email, FILTER_VALIDATE_EMAIL)) { //email validation
$output = json_encode(array('type'=>'error', 'text' => 'Please enter a valid email.'));
die($output);
}
//subject
$subject = "The Story";
//email body
$message_body = "Email : ".$user_trial_email."\r\nApp link:https://play.google.com/apps/testing/com.salefee.salefee.salefee\r\nWe will shortly send you the whole story";
//proceed with PHP email.
$headers = 'From: '."salefee12@gmail.com".''."\r\n".
'Reply-To: '.$user_trial_email.''."\r\n".
'X-Mailer: PHP/'.phpversion();
$send_mail = mail($to_email, $subject, $message_body, $headers);
if (!$send_mail)
{
//If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens)
$output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
die($output);
} else {
$output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_trial_name.', Thank you for subscribing. You will soon get a link to download app.'));
die($output);
}
}
?>
Can someone help me out with this code...Thanks in advance!!
First you need to give name to your submit button:
<button class="btn btn-danger" type="submit" name="submit">Sign Up</button>
And then in your php file:
if (isset($_POST("submit")) {
PHP:
if ($_POST['signup']) {
//your script which you want to execute as soon as form submitted
}
HTML:
<button class="btn btn-danger" type="submit" name="signup">Sign Up</button>
Read more about how to use $_POST[]
In PHP data is passed by name not id. So your HTML code should look like this
<input class="form-control" id="newsletter-email" **name**="newsletter-email" name="newsletter-email" type="email" placeholder="Enter email">
And then your PHP file should work if you get data like this
$_POST["newsletter-email"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.