php电子邮件发送脚本不发送电子邮件 [英] php email sending script not sending email

查看:151
本文介绍了php电子邮件发送脚本不发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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..

thanx帮助我

<?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()

First of all, your query is SQL injectable. Never ever pass a variable coming from a POST request directly into an SQL query. Use mysql_real_escape().

对于你的错误:似乎 $ user 不包含有效的电子邮件地址。所以,Mysql查询没有返回电子邮件地址。

As to your bug: it seems that $user does not contain a valid e-mail address. so, the Mysql query is not returning an e-mail address.

使用$ _POST而不是$ HTTP_POST_VARS。

Use $_POST rather than $HTTP_POST_VARS.

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

Switch on error reporting by prepending these two lines to your 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);

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

just before the line that has the mysql_query command, and then run the query manually (e.g. using PhpMyAdmin or MySQL Query Browser) to see if you are actually getting a result that looks like an e-mail address.

这篇关于php电子邮件发送脚本不发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆