网站来源:http://www.salefee.com/
有人能查一下我上面提到的网站吗.我在“收卖故事电子书,提交你的电子邮件”下做了一份表格
我做了一个表单,用户提交他的电子邮件id,然后表单是链接到一个php文件发送电子邮件到用户电子邮件id。问题是表单没有被重定向到.php文件。我在HTML中添加了action和method属性。当用户单击submit按钮时,不会执行php代码。
HTML代码如下:
<!-- 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 -->我的php代码名为story.php,如下所示:
<?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);
}
}
?>有人能帮我把这个code...Thanks提前!
发布于 2016-06-08 07:01:16
首先,您需要为提交按钮指定名称:
<button class="btn btn-danger" type="submit" name="submit">Sign Up</button>然后在php文件中:
if (isset($_POST("submit")) {发布于 2016-06-08 07:36:29
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>了解有关如何使用$_POST[]的更多信息
http://php.net/manual/en/reserved.variables.post.php
发布于 2016-06-08 07:30:51
在PHP中,数据是通过名称而不是id传递的。所以HTML代码应该如下所示
<input class="form-control" id="newsletter-email" **name**="newsletter-email" name="newsletter-email" type="email" placeholder="Enter email">
如果您得到这样的数据,那么PHP文件应该可以工作。
$_POST["newsletter-email"]https://stackoverflow.com/questions/37695053
复制相似问题