尝试同时向用户和管理员发送邮件

Trying to send mail to user and admin at same time

<?php
include("include/head.php");
include("include/headder.php"); 
if(isset($_POST['submitfrm']))
{
if($_REQUEST['captchares'] != 1)
{
echo "<script> window.location='page-full-width.php?capterror'; </script>"; 
exit;
}
else
{
$username=$_REQUEST['username'];
$useremail=$_REQUEST['useremail'];
$mobile=$_REQUEST['mobile'];
$comment=$_REQUEST['comment'];  


$contact=mysql_query("INSERT INTO `contactus` (`username`, `useremail`, `mobile`, `comment`) VALUES ('$username', '$useremail', '$mobile', '$comment')");


$conatctid=mysql_insert_id();


if($contact)
{

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
//$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = $smtphost;
$mail->Port = 25; // or 587
$mail->IsHTML(true);
$mail->Username = $smtpmail;
$mail->Password = $smtppassword;
$mail->SetFrom = $smtpmail;
$mail->Subject = "Enquiry";
$mail->Body = "<table cellpadding='0' cellspacing='0' border='0' bgcolor='#006699' style='border:solid 10px #006699; width:550px;'>
<tr bgcolor='#006699' height='25'>
<td><img src='$sitelogo' border='0' width='200' height='60' /></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td>&nbsp;</td>
</tr>
<tr bgcolor='#FFFFFF' height='30'>
<td valign='top' style='font-family:Arial; font-size:12px; line-height:18px; text-decoration:none; color:#000000; padding-left:20px;'>This mail is sent from <b> $website_name </b> Regarding your enquiry</td></tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'>Our support team will get you soon,  Dear $username </td>
</tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'>We will response to :$useremail</td>
</tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'>Our notifications and offers sent as per your willingness to :$mobile</td>
</tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'>Your enquiry :$comment</td>
</tr>
</table>";
$mail->AddAddress($useremail);
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
//==================================Send mail to admin==========================================

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
//$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = $smtphost;
$mail->Port = 25; // or 587
$mail->IsHTML(true);
$mail->Username = $smtpmail;
$mail->Password = $smtppassword;
$mail->SetFrom = $useremail;
$mail->Subject = "Enquiry";
$mail->Body = "<table cellpadding='0' cellspacing='0' border='0' bgcolor='#006699' style='border:solid 10px #006699; width:550px;'>
<tr bgcolor='#006699' height='25'>
<td><img src='$sitelogo' border='0' width='200' height='60' /></td>
</tr>
<tr bgcolor='#FFFFFF'><td>&nbsp;</td></tr>
<tr bgcolor='#FFFFFF' height='30'>
<td valign='top' style='font-family:Arial; font-size:12px; line-height:18px; text-decoration:none; color:#000000; padding-left:20px;'>This mail is sent from <b> $website_name </b> Regarding your enquiry</td></tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'>User Name: $username </td>
</tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'>User Email: $useremail</td>
</tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'>User Mobile: $mobile</td>
</tr>
<tr bgcolor='#FFFFFF' height='35'>
<td style='padding-left:20px; font-family:Arial; font-size:11px; line-height:18px; text-decoration:none; color:#000000;'>User enquiry :$comment</td>
</tr>
</table>";
$mail->AddAddress($website_admin);
//==============================================================================================
echo "<script> window.location='page-full-width.php?sent'; </script>"; 
exit;

}
}
}
}

邮件发送给用户但邮件收不到管理员..请帮帮我.. 我想在用户发送查询时向用户发送邮件,以及在用户查询产品时向管理员发送邮件。

您没有为代码的 "Send mail to admin" 部分调用 $mail->Send();

,我会 post 它作为答案,因为它似乎是你问题的根源。

您忘记在 $mail->AddAddress($website_admin); 之后写 $mail->Send();

这就是邮件未发送的原因。你没有告诉 PHP 这样做。

添加这一行(就像您在第一封电子邮件中所做的那样),您就可以开始了。