我有以下代码发布到MySQL数据库并发送包含数据的电子邮件。一切正常,但电子邮件不包含实际的可变数据,只包含其他电子邮件txt。我知道我做错了什么?
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO mes_demo (`first`, `last`, email, credit_union, `date`) VALUES (%s, %s, %s, %s, NOW())",
GetSQLValueString($_POST['first'], "text"),
GetSQLValueString($_POST['last'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['credit_union'], "text"),
GetSQLValueString($_POST['date'], "date"));
mysql_select_db($database_MESdemo, $MESdemo);
$Result1 = mysql_query($insertSQL, $MESdemo) or die(mysql_error());
$to = "mike@michaelneill.com;tony@michaelneill.com";
$subject = "MES Demo Viewed";
$txt = "The following person has submitted a form to view the MES Demo\r\n
Name: $first $last\r\n
E-mail: $email\r\n
Credit Union: $credit_union";
$headers = "From: Tony Hendrix <tony@michaelneil.com>";
mail($to,$subject,$txt,$headers);
$insertGoTo = "demo.html";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
答案 0 :(得分:0)
您尝试使用$first
和$credit_union
等变量而不定义它们。
使用$_POST['first']
代替,或者定义您尝试使用的变量:
$first = $_POST['first']
答案 1 :(得分:0)
$first = $_POST['first'];
$last = $_POST['last'];
$email = $_POST['email'];
$credit_union = $_POST['credit_union'];
$date = $_POST['date'];
答案 2 :(得分:0)
我认为这是一些你正在使用的旧PHP代码,因为它似乎使用的是PHP寄存器_globals,它在PHP 5.3中被弃用,最后从PHP 5.4中删除
您可以在此处了解详情: http://php.net/manual/en/security.globals.php
然而,正如其他人指出的那样,您必须首先定义这些变量:
$first = $_POST['first'];
$last = $_POST['last'];
$email = $_POST['email'];
$credit_union = $_POST['credit_union'];
$date = $_POST['date'];
其次,如果你不想改变。你应该看一下extract()函数:http://php.net/extract
先试试这个:
extract($_POST);
像这样:
extract($_POST, EXTR_SKIP);
$to = "mike@michaelneill.com;tony@michaelneill.com";
$subject = "MES Demo Viewed";
$txt = "The following person has submitted a form to view the MES Demo\r\n
Name: $first $last\r\n
E-mail: $email\r\n
Credit Union: $credit_union";
$headers = "From: Tony Hendrix <tony@michaelneil.com>";
mail($to,$subject,$txt,$headers);