有人可以查看我上面提到的网站吗?我已经在“要接收促销故事电子书,请提交您的电子邮件 ID”下制作了一份表格
我制作了一个表单,用户在其中提交他的电子邮件 ID,然后表单链接到一个 php 文件,该文件将电子邮件发送到用户电子邮件 ID。
问题是表单没有重定向到 .php 文件。我在 HTML 表单中添加了 action
和 method
属性。当用户单击提交按钮时,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 -->
我的名为story.php的php代码如下:
<?php
if ($_POST) {
$to_email = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ceffdf0f9faf9f9adaedcfbf1fdf5f0b2fff3f1" rel="noreferrer noopener nofollow">[email protected]</a>" //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: '."<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aeddcfc2cbc8cbcb9f9ceec9c3cfc7c280cdc1c3" rel="noreferrer noopener nofollow">[email protected]</a>".''."\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);
}
}
?>
有人可以帮我解决这个代码...提前致谢!!
最佳答案
首先,您需要为提交按钮命名:
<button class="btn btn-danger" type="submit" name="submit">Sign Up</button>
然后在你的 php 文件中:
if (isset($_POST("submit")) {
关于php - html 中的表单没有重定向到 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37695053/