0

我已经测试了此代码以使用本地服务器工具发送电子邮件,它工作正常,但在“发件人”部分我没有收到发件人电子邮件,因为它应该在那里打印到 $email ,而不是我得到这个输出“来自:资源 id #6”,究竟是什么问题,因为查询看起来很好并且工作?

这部分代码

$Load=$_SESSION['login_user'];
$smail= "Select email from teacher where TID = $Load ";

$errors = '';
  $email= mysql_query($smail);  
if( 
   empty($_POST['email']) || 
   empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}


$email_address = $_POST['email']; 
$message = $_POST['message']; 

if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email_address))
{
    $errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
    $to = $email_address; 
    $email_subject = "New mail from admin";
    $email_body = "You have received a new message. ".
    " Here are the details:\n From: $email \n Message \n $message"; 

    $headers = "From: $email\n"; 
    $headers .= "Reply-To: $email_address";

    $sent = mail($to,$email_subject,$email_body,$headers);      
}
4

3 回答 3

1

执行查询后您没有获取记录,试试这个

$result = mysql_fetch_assoc(mysql_query($smail));  
$email = $result['email']
于 2012-12-25T11:32:06.387 回答
1

使用 mysql_fetch_assoc

 $result = mysql_fetch_assoc(mysql_query($email));  
 $email = $result['email']
于 2012-12-25T11:35:25.637 回答
0

您必须先获取结果。

$result= mysql_query($email);  
$row=mysql_fetch_object($result);
$email=$row->email;
于 2012-12-25T11:32:53.967 回答