[英]php email sending script not sending email
following is my script for send email inquiry.. the recipient email address was stored in a db called users.. this script will not work properly.. i think the problem is recipient email section.. because when i used a email address instead of $user it will work.. 以下是我发送电子邮件查询的脚本。.收件人电子邮件地址存储在名为users的数据库中。.该脚本无法正常工作..我认为问题是收件人电子邮件部分..因为当我使用电子邮件地址而不是$ user它会工作..
thanx help me 谢谢我
<?php
$refno = $HTTP_POST_VARS['refno'];
$proid = $HTTP_POST_VARS['proid'];
$name = $HTTP_POST_VARS['name'];
$email = $HTTP_POST_VARS['email'];
$msg = $HTTP_POST_VARS['msg'];
//connect db and find email address related to id
include 'db_connector.php';
$id=$HTTP_POST_VARS['id'];
$query=mysql_query("SELECT user_email FROM users WHERE id='".$id."'");
$cont=mysql_fetch_array($query);
$user=$cont['user_email'];
// recipient name
$recipientname = "'".$name."'";
// recipient email
$recipientemail = $user ;
// subject of the email sent to you
$subject = "Inquiry for your advertisement No. (".$refno.")";
// send an autoresponse to the user?
$autoresponse = "no";
// subject of autoresponse
$autosubject = "Thank you for your inquiry!";
// autoresponse message
$automessage = "Thank you for your inquiry.! We'll get back to you shortly.
";
// END OF NECESSARY MODIFICATIONS
$message = "reference number : $refno
$msg
From $name $email
---";
// send mail and print success message
mail($recipientemail,"$subject","$message","From: $recipientname <$email>");
if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}
header("Location:index.php");
exit;
?>
First of all, your query is SQL injectable. 首先,您的查询是SQL可注入的。 Never ever pass a variable coming from a POST request directly into an SQL query.
永远不要将来自POST请求的变量直接传递到SQL查询中。 Use
mysql_real_escape()
. 使用
mysql_real_escape()
。
As to your bug: it seems that $user
does not contain a valid e-mail address. 关于您的错误:
$user
似乎不包含有效的电子邮件地址。 so, the Mysql query is not returning an e-mail address. 因此,Mysql查询不会返回电子邮件地址。
Use $_POST rather than $HTTP_POST_VARS. 使用$ _POST而不是$ HTTP_POST_VARS。
Switch on error reporting by prepending these two lines to your PHP code: 通过将以下两行添加到您的PHP代码中来打开错误报告:
PHP code: PHP代码:
error_reporting(E_ALL);
ini_set('display_errors','1');
Run your script again. 再次运行脚本。 Do you get any notices or warnings?
您收到任何通知或警告吗?
If not, try to display your query, by adding 如果不是,请尝试通过添加
die($query);
just before the line that has the mysql_query
command, and then run the query manually (eg using PhpMyAdmin or MySQL Query Browser) to see if you are actually getting a result that looks like an e-mail address. 在具有
mysql_query
命令的行之前,然后手动运行查询(例如,使用PhpMyAdmin或MySQL查询浏览器)以查看您是否实际上得到的结果看起来像电子邮件地址。
Debug your PHP program. 调试您的PHP程序。
Check out : 查看 :
PHP manual have a good example to send mail. PHP手册中有一个很好的发送邮件的例子。
Do not use $HTTP_POST_VARS['name'];
不要使用
$HTTP_POST_VARS['name'];
it is deprecated use $_POST
instead. 不推荐使用
$_POST
代替。
hey guys thanx for the help.. i found the error done in my inquiry form.. the id filed hidden outside of the form tag.. therefore the id value will not passed to the sendinq.php. 嘿,thanx寻求帮助。.我在查询表单中发现错误。.id字段隐藏在表单标签之外..因此,id值不会传递给sendinq.php。 i change it thank now the sendmail option work properly
我更改它,现在谢谢sendmail选项可以正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.