简体   繁体   English

$ _POST似乎不起作用

[英]$_POST doesn't seem to work

I'm creating an e-mail system, so I made this little test tidbit and it works.....a bit? 我正在创建一个电子邮件系统,所以我做了这个小测试花絮,它可以工作.....有点吗?

 <html> <head><title>EMail Test</title></head> <body> <input type="text" name="email"> EMail (required) <br><br> <textarea name="comment" rows="5" cols="40"></textarea> what's your problem? <br><br> <form method="POST" action=''> <input type="submit" name="button1" value="Submit"> </form> <?php if (isset($_POST['button1'])) { $msg=$_POST['email']." asks: ".$_POST['comment']; echo $msg; $email=$_POST['email']; $SupportNinga="Typhoone01@gmail.com"; $mail=mail($SupportNinga,"Question from ".$email,$msg); echo "Emailing..."; if($mail) { echo"E-mail sent sucessfully"; } } ?> </body> </html> 

This was put into an online host and didn't seem to work. 这被放到在线主机上,似乎没有用。

It sent the e-mail, but it simply said "Question from-asks:". 它发送了电子邮件,但只说了“发问的问题:”。 I can tell it's not properly reading the $_POST. 我可以知道它没有正确读取$ _POST。

Help is appriciated. 寻求帮助。 :P :P

Firstly, this part of your code is outside your form. 首先,代码的这一部分不在表单中。

<textarea name="comment" rows="5" cols="40"></textarea> what's your problem?

As is <input type="text" name="email"> <input type="text" name="email">

Place all form elements inside <form></form> tags. 将所有表单元素放在<form></form>标记内。

Your mail() parameters are also off. 您的mail()参数也已关闭。

Read the manual http://php.net/manual/en/function.mail.php 阅读手册http://php.net/manual/en/function.mail.php

Use error reporting. 使用错误报告。

Add error reporting to the top of your file(s) which will help find errors. 错误报告添加到文件顶部,这将有助于发现错误。

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: Displaying errors should only be done in staging, and never production. 旁注:显示错误仅应在登台中进行,而不应在生产中进行。


You should also check for empty() 'ness on your email input. 您还应该在电子邮件输入中检查是否为empty()

Also using FILTER_VALIDATE_EMAIL against it: 还要FILTER_VALIDATE_EMAIL使用FILTER_VALIDATE_EMAIL


HTML sticklers: HTML贴纸:

In regards to using <html> it's best to declare a doctype, such as <!DOCTYPE html> . 关于使用<html> ,最好声明一个doctype,例如<!DOCTYPE html>

Firefox for one, will throw a (red) warning in HTML source, upon placing your mouse over <html> . 将Firefox放在<html>时,Firefox的一个会在HTML源代码中引发(红色)警告。

Such as: 如:

Start tag seen without seeing a doctype first. 开始看到标记,但没有先看到doctype。 Expected "<!DOCTYPE html>" . 预期为"<!DOCTYPE html>"

  • <form method="POST" action=''> be consistent and use all double quotes. <form method="POST" action=''>要保持一致,并使用所有双引号。

  • Seperate your PHP from HTML. 将PHP与HTML分开。 Place your PHP above your HTML if you're not going to be echoing anything special besides your "success on mail" message. 如果您不打算回显“邮件成功”消息以外的任何特殊内容,请将PHP置于HTML之上。


Prevent data resubmissions: 防止重新提交数据:

You should be redirecting to a new page using a header, and using sessions/tokens to prevent people from resubmitting the same data if the user refreshes that page. 您应该使用标题重定向到新页面,并使用会话/令牌来防止用户刷新该页面时人们重新提交相同的数据。

References: 参考文献:

XSS injection: XSS注入:

$msg=$_POST['email']." asks: ".$_POST['comment'];

You should first declare your variables assigned from your POST arrays, then concatenate those variables. 您应该首先声明从POST数组分配的变量,然后将这些变量连接起来。 You stand at getting an XSS injection here. 您站在这里获得XSS注入。

References: 参考文献:


User sign-up via email footnote: 通过电子邮件脚注进行用户注册

"I'm creating an e-mail system" . “我正在创建一个电子邮件系统”

It seems you're new to working with emailing, and here are a few pointers for you. 看来您是第一次接触电子邮件,这里为您提供了一些提示。

You need to make sure that you include an unsubscribe method in each mailing. 您需要确保在每个邮件中都包含一个取消订阅的方法。

There are laws about this, and is beyond the scope of this question. 有关于此的法律,超出了此问题的范围。

Canada for one and being my country, has strict anti-spam laws, as do other countries. 作为一个国家,加拿大与其他国家一样,拥有严格的反垃圾邮件法律。

So, make sure that the people who sign up, know what they're getting themselves into and have an double opt-in method for verification. 因此,请确保注册人员,知道自己所要学习的内容以及采用双重选择加入方式进行验证的人。

Otherwise, you will get blacklisted. 否则,您将被列入黑名单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM