请使用以下代码寻求帮助:
if( !$error ) {
move_uploaded_file($file_loc,$folder.$file);
$cuser = $userRow['userName'];
$res = mysql_query("SELECT * FROM users WHERE userId=".$_SESSION['user']);
$userRow = mysql_fetch_array($res);
$query = "INSERT INTO postoffers(postedby,reqName,reqEmail,reqHotel,reqOutlet,reqCnum,reqPostType,reqPostHead,reqPostDet,offerStarts,offerEnds,file,type,size) VALUES('$cuser','$rname','$remail','$rhotel','$routlet','$rcnum','$rposttype','$rposthead','$rpostdet','$rbdate','$redate','$file','$file_type','$file_size')";
$res = mysql_query($query);
if ($res) {
$errTyp = "success";
$errMSG = "Successfully Posted!";
unset($rname);
unset($remail);
unset($rhotel);
unset($routlet);
unset($rcnum);
unset($rposttype);
unset($rposthead);
unset($rpostdet);
unset($rbdate);
unset($redate);
unset($file);
$to = ;
$subject = "Your Post Offer";
$message = "Thank you " . $cuser . " for the Post Request.";
$headers = 'From: AFP Webmaster' . "\r\n" .
$headers = "MIME-Version: 1.0" . "\r\n" .
$headers = "Content-type:text/html;charset=iso-8859-1" . "\r\n" .
'Reply-To: AFP Webmaster' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
else {
$errTyp = "danger";
$errMSG = "Something went wrong, try again later...";
}
}
代码完美地完成以下工作: 1.将值存储在DB上。 2.如果我在$ to中将“name@gmail.com”等有效电子邮件发送到
我现在想要的是从数据库中分配“reqEmail”的值或将文本字段“remail”中的值分配给$ to。
因此,电子邮件将转到填写表单的电子邮件中。
我希望我让自己清楚易懂。
谢谢!
答案 0 :(得分:0)
您在发送电子邮件之前清除变量,因此PHP不知道将电子邮件发送到的位置。您需要在PHP Mailer调用之后放置“未设置”函数。试试这个:
if (!$error) {
move_uploaded_file($file_loc, $folder.$file);
$cuser = $userRow['userName'];
$res = mysql_query("SELECT * FROM users WHERE userId=".$_SESSION['user']);
$userRow = mysql_fetch_array($res);
$query = "INSERT INTO postoffers(postedby,reqName,reqEmail,reqHotel,reqOutlet,reqCnum,reqPostType,reqPostHead,reqPostDet,offerStarts,offerEnds,file,type,size) VALUES('$cuser','$rname','$remail','$rhotel','$routlet','$rcnum','$rposttype','$rposthead','$rpostdet','$rbdate','$redate','$file','$file_type','$file_size')";
$res = mysql_query($query);
if ($res) {
$to = ;
$subject = "Your Post Offer";
$message = "Thank you " . $cuser . " for the Post Request.";
$headers = 'From: AFP Webmaster' . "\r\n".
$headers .= "MIME-Version: 1.0" . "\r\n".
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n" . 'Reply-To: AFP Webmaster' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
$errTyp = "success";
$errMSG = "Successfully Posted!";
unset($rname);
unset($remail);
unset($rhotel);
unset($routlet);
unset($rcnum);
unset($rposttype);
unset($rposthead);
unset($rpostdet);
unset($rbdate);
unset($redate);
unset($file);
} else {
$errTyp = "danger";
$errMSG = "Something went wrong, try again later...";
}
}