0

我在这里有一个代码可以向客户和管理员发送电子邮件。到目前为止它正在发送给客户,但我无法弄清楚为什么它没有发送给管理员请帮忙。

$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;
4

3 回答 3

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;;
}
于 2013-09-17T04:45:29.890 回答
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);
?>

只需确保在不在本地主机中的实时服务器上进行测试

于 2013-09-17T05:09:48.037 回答
0

使用邮件代码两次

最后把下面的代码

if(!$mail->Send())
{
   echo "Error sending: " . $mail->ErrorInfo;;
}
于 2013-09-17T05:31:38.243 回答