我正在使用PHPMailer在我的Joomla项目中发送电子邮件。当我发送电子邮件到和发送两个地址时,这两个人都会收到电子邮件,但在电子邮件中我们只能看到姓名所在的人。感觉好像该人被发送为“密件抄送”,因此未在电子邮件中显示。这种行为有点奇怪。
这里的任何帮助都会很棒。
以下是代码:
class EmailService {
public function __construct($from_address = NULL, $from_name = NULL) {
$config = & JFactory::getConfig();
$from_address = isset($from_address) ? $from_address : $config->getValue('config.mailfrom');
$from_name = isset($from_name) ? $from_name : $config->getValue('config.fromname');
$sender = array(
$from_address,
$from_name
);
$this->mailer = JFactory::getMailer ( );
$this->mailer->setSender($sender);
}
public function sendMail($recipient, $subject, $body, $type = 'html', $cc = null, $bcc = null, $attachment = null, $replyto = null, $replytoname = null) {
if (!isset($this->mailer)) {
throw new Exception("No mailer instance found!");
}
$this->mailer->addRecipient($recipient);
$this->mailer->setSubject($subject);
$this->mailer->setBody($body);
if ($type == "html") {
$this->mailer->isHTML(true);
}
if (isset($cc)) {
$this->mailer->addCC($cc);
}
if (isset($bcc)) {
$this->mailer->addBCC($bcc);
}
if (isset($attachment)) {
$this->mailer->addAttachment($attachment);
}
if (is_array($replyto)) {
$numReplyTo = count($replyto);
for ($i = 0; $i < $numReplyTo; $i++) {
$this->mailer->addReplyTo(array($replyto[$i], $replytoname[$i]));
}
} elseif (isset($replyto)) {
$this->mailer->addReplyTo(array($replyto, $replytoname));
}
return $send = & $this->mailer->Send();
}
[编辑] 以下是用法摘录
$recipient = array ("abc@abc.com");
$cc = array ("cc@cc.com");
$emailType = 'html';
$emailBody = "Some HTML content";
$this->emailService->sendMail($recipient, "Some Subject", $emailBody, $emailType, $cc);
答案 0 :(得分:0)