我已经测试了此代码以使用本地服务器工具发送电子邮件,它工作正常,但在“发件人”部分我没有收到发件人电子邮件,因为它应该在那里打印到 $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);
}