![](http://e.hiphotos.baidu.com/image/pic/item/4034970a304e251f39cdd5caa086c9177f3e53cd.jpg?v=tbs)
PHP E-mail 注入
<html><body><?phpif (isset($_REQUEST['email']))//if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail("someone@example.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; }else//if "email" is not filled out, display the form { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; }?></body></html>
以上代码存在的问题是,未经授权的用户可通过输入表单在邮件头部插入数据。
假如用户在表单中的输入框内加入这些文本,会出现什么情况呢?
<html><body><?phpif (isset($_REQUEST['email']))//if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail("someone@example.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; }else//if "email" is not filled out, display the form { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; }?></body></html>
以上代码存在的问题是,未经授权的用户可通过输入表单在邮件头部插入数据。
假如用户在表单中的输入框内加入这些文本,会出现什么情况呢?
![](http://e.hiphotos.baidu.com/image/pic/item/4034970a304e251f39cdd5caa086c9177f3e53cd.jpg?v=tbs)