我这里有一个代码,可以向客户端和管理员发送电子邮件。到目前为止,它已发送给客户端,但我无法弄清楚为什么它没有发送给管理员请帮助。
$mail = new PHPMailer();
$mail->IsMail();
$mail->AddAddress($email);
$mail->Subject = $subject;
$mail->IsHTML(true);
$mail->From= $admin_email;
$mail->FromName= "Chinchilla Scientific";
$mail->Body = $user_message;
if(!$mail->Send())
{
echo "Error sending: " . $mail->ErrorInfo;;
}
$mail = new PHPMailer();
$mail->IsMail();
$mail->AddAddress($admin_email);
$mail->Subject = $subject;
$mail->IsHTML(true);
$mail->From = $email;
$mail->FromName= $name;
$mail->Body = $admin_message;
exit;
答案 0 :(得分:1)
尝试这个......你不需要使用它两次
$mail = new PHPMailer();
$mail->IsMail();
$mail->AddAddress($email);
$mail->AddBCC($admin_email); // change here
$mail->Subject = $subject;
$mail->IsHTML(true);
$mail->From= $admin_email;
$mail->FromName= "Chinchilla Scientific";
$mail->Body = $user_message;
if(!$mail->Send())
{
echo "Error sending: " . $mail->ErrorInfo;;
}
答案 1 :(得分:0)
您可以直接使用PHP邮件功能而无需使用PHP邮件程序
<?php
// multiple recipients
$to = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
请务必在不在localhost
中的实时服务器上测试答案 2 :(得分:0)
使用邮件代码twince
最后将代码放在下面
if(!$mail->Send())
{
echo "Error sending: " . $mail->ErrorInfo;;
}