簡體   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