【问题标题】:PHP send main answerPHP发送主要答案
【发布时间】:2014-09-02 11:22:53
【问题描述】:

我是 php 的第一步,我已经发送邮件表单,它包含在另一个页面中,所以实际上它是通过 index.php?email=support 和 index.php 工作的只提供信息。

表单正在工作 index.php?email=support,一旦发送,它只是刷新页面到 index.php 插入 index.php? email=support 应该给出发送电子邮件的答案。据我了解,它应该通过表单发送到页面链接

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">

请帮助......

谢谢!

【问题讨论】:

  • 你的 index.php 文件的代码是什么? (仅有用的部分)
  • 这里是副本:jsfiddle.net/3s4rubcm
  • 你不应该使用PHP_SELF,因为这很容易被跨站点脚本。试试index.php?email=support&amp;somethingelse="&gt;&lt;b&gt;Hello&lt;/b&gt;"
  • 你的意思是使用 "index.php?email=support" insted of "echo $_SERVER['PHP_SELF']"???

标签: php sendmail


【解决方案1】:
$_SERVER['PHP_SELF']

仅返回脚本名称并跳过任何请求变量,例如 email=support。您需要将操作更改为:

<form method="post" action="/index.php?email=support&send=1" id="contactform">

根据 $_GET['send'] 变量,您将能够判断消息是否已发送,以及系统是否应显示消息确认它已发送:

if (!empty($_GET['send']))
{
    echo 'Message successfully send!';
}

【讨论】:

  • 已经有答案了:

    再次检查

    sent

    已发送

  • 但是,使用“PHP_SELF”怎么样 刚刚在网上查了一些资料,这不是最好的选择,是吗???
  • 好的,你真的是在提交表格后设置$emailSent吗?如果没有:它不会有任何影响。关于您不使用 PHP_SELF 的评论:PHP_SELF 确实让您容易受到 XSS 攻击。您不妨使用 index.php?email=support&send=1,我相应地更新了我的答案。
  • 是的,看起来 gr8,但是:
    干杯!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-12
  • 2016-06-08
  • 1970-01-01
  • 1970-01-01
  • 2015-03-25
  • 1970-01-01
  • 2013-08-02
相关资源
最近更新 更多