繁体   English   中英

PHP的电子邮件发送脚本不发送电子邮件

[英]php email sending script not sending email

以下是我发送电子邮件查询的脚本。.收件人电子邮件地址存储在名为users的数据库中。.该脚本无法正常工作..我认为问题是收件人电子邮件部分..因为当我使用电子邮件地址而不是$ user它会工作..

谢谢我

<?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;

?>

首先,您的查询是SQL可注入的。 永远不要将来自POST请求的变量直接传递到SQL查询中。 使用mysql_real_escape()

关于您的错误: $user似乎不包含有效的电子邮件地址。 因此,Mysql查询不会返回电子邮件地址。

使用$ _POST而不是$ HTTP_POST_VARS。

通过将以下两行添加到您的PHP代码中来打开错误报告:

PHP代码:

error_reporting(E_ALL);
ini_set('display_errors','1');

再次运行脚本。 您收到任何通知或警告吗?

如果不是,请尝试通过添加

die($query);

在具有mysql_query命令的行之前,然后手动运行查询(例如,使用PhpMyAdmin或MySQL查询浏览器)以查看您是否实际上得到的结果看起来像电子邮件地址。

调试您的PHP程序。

查看 :

  • 如果变量包含假定值。
  • 查询还可以,并返回结果。
  • 通过邮件功能设置适当的标题。
  • 等等

PHP手册中有一个很好的发送邮件的例子。

不要使用$HTTP_POST_VARS['name']; 不推荐使用$_POST代替。

嘿,thanx寻求帮助。.我在查询表单中发现错误。.id字段隐藏在表单标签之外..因此,id值不会传递给sendinq.php。 我更改它,现在谢谢sendmail选项可以正常工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM