简体   繁体   中英

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(); right after $mail->AddAddress($website_admin); .

That is why the mail hasn't been sent. You haven't told PHP to do so.

Add this line (as you did for the first email) and you'd be good to go.

You did not call $mail->Send(); for your "Send mail to admin" part of your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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