【问题标题】:php email sending script not sending emailphp电子邮件发送脚本不发送电子邮件
【发布时间】:2011-09-16 06:40:12
【问题描述】:

以下是我发送电子邮件查询的脚本.. 收件人电子邮件地址存储在名为 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;

?>

【问题讨论】:

  • 检查您从查询中获得的电子邮件地址是否正确。

标签: php email send


【解决方案1】:

调试您的 PHP 程序。

退房:

  • 如果变量包含假定值。
  • 查询正常并返回结果。
  • 使用邮件功能设置正确的标题。

PHP manual 有一个发送邮件的好例子。

不要使用$HTTP_POST_VARS['name'];,不推荐使用$_POST

【讨论】:

    【解决方案2】:

    首先,您的查询是 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 查询浏览器)以查看您是否真的得到了一个看起来像电子邮件地址的结果。

    【讨论】:

    • 我改成了 $_POST,我也添加了错误代码,现在 $id=$_POST['id'];行,并且表中存在有效的电子邮件 ID 错误是 Notice: Undefined index: id in /sendinq.php on line 14
    • 第 14 行是引用 $_POST['id'] 的行吗?在这种情况下:您确定您的请求中实际上有一个名为“id”的 POST 变量吗?
    【解决方案3】:

    大家好,thanx 的帮助.. 我在查询表单中发现错误.. id 文件隐藏在表单标签之外.. 因此 id 值不会传递给 sendinq.php。我更改了它,谢谢现在 sendmail 选项可以正常工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-12
      • 2011-04-28
      • 2014-08-17
      • 1970-01-01
      • 2015-01-20
      • 1970-01-01
      相关资源
      最近更新 更多