简体   繁体   English

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

[英]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;

}
}
}
}

Mail sending to user but mail not receiving to admin.. help me out please.. I want to send mail to user when he send inquiry and as well as to admin as user inquiry about the product. 向用户发送邮件,但不向管理员发送邮件。请帮助我。我想在用户发送查询以及向用户发送有关产品的查询时向用户发送邮件。

Following my comment , I'll post it as an answer as it seems to be the source of your problem. 在发表评论之后 ,我将其发布为答案,因为这似乎是您问题的根源。

You forgot to write $mail->Send(); 您忘记写$mail->Send(); right after $mail->AddAddress($website_admin); $mail->AddAddress($website_admin); .

That is why the mail hasn't been sent. 这就是为什么尚未发送邮件的原因。 You haven't told PHP to do so. 您尚未告诉PHP这样做。

Add this line (as you did for the first email) and you'd be good to go. 添加此行(就像您对第一封电子邮件所做的那样),您将很高兴。

You did not call $mail->Send(); 您没有调用$mail->Send(); for your "Send mail to admin" part of your code. 代码的“发送邮件给管理员”部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM