PHP邮件添加\如果有"或者'在变量中

时间:2013-05-09 19:57:39

标签: php email

我制作了一个电子邮件脚本,用于向用户发送填写在表单中的信息。但我们注意到,当我们使用“或”发送任何信息时,它会在电子邮件中添加“或”。现在我明白PHP要求它不要过早地破坏它,但有什么方法可以解决这个问题吗?

以下是我的问题示例...... 多尔蒂的建构

   //SEND EMAIL TO name@website.com
    $to      = "name@website.com";
    $subject = "Sending Company Name - Receipt " . $_POST['company'];
    $header = "From: name@website.com" . "\r\n";
    $header .= "Reply-To: " . $_POST['email'] . "\r\n";
    $header .= "MIME-Version: 1.0" . "\r\n";
    $header .= "Content-type: text/html;charset=iso-8859-1" . "\r\n";
    $message = "<html>
                    <body>
                        <img alt='Logo' src='http://www.website.com/logo.png'/>
                        <h2>
                            Customer Payment
                        </h2>
                        <p><b>Company:          </b>" . $_POST["company"] . "</p>
                        <p><b>Name:             </b>" . $_POST['first_name'] . " " . $_POST['last_name'] . "</p>
                        <p><b>Email:            </b>" . $_POST['email'] . "</p>
                        <p><b>Phone:            </b>" . $_POST['phone'] . "</p>
                        <p><b>Location:         </b>" . $_POST['city'] . ", " . $_POST['state'] . " " . $_POST['zip'] . "</p>
                        <p><b>Date:             </b>" . $today = date('F j, Y - g:i A (T)') . "</p>
                        <p><b>Card Used:        </b> XXXX-XXXX-XXXX-" . $last4 . "</p>
                        <p><b>Payment Amount:   </b>$" . $_POST['price'] . "</p>
                        <br/>
                        <p>http://www.website.com/payment</p>
                    </body>
                </html>";
    mail($to, $subject, $message, $header);

2 个答案:

答案 0 :(得分:1)

正如其他人评论它一样,因为你启用了魔法引号。您应该禁用它,或者您可以处理输入以解决问题,例如。

<?php 
function fix_magic_quotes_gpc(&$value, $key){
    if (get_magic_quotes_gpc()) {
        $value = stripslashes($value);
        $key   = stripslashes($key);
    }
}
$inputs = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
array_walk_recursive($inputs, 'fix_magic_quotes_gpc');
?>

答案 1 :(得分:0)

我知道两种方式: 1)禁用魔术引号

if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
while (list($key, $val) = each($process)) {
    foreach ($val as $k => $v) {
        unset($process[$key][$k]);
        if (is_array($v)) {
            $process[$key][stripslashes($k)] = $v;
            $process[] = &$process[$key][stripslashes($k)];
        } else {
            $process[$key][stripslashes($k)] = stripslashes($v);
        }
    }
}
unset($process);
}

2)使用html实体: 你可以使用&amp;#34;或者&amp; quot;为“和&amp;#39;或&amp;';为'。