即時通訊使用以下php代碼發送電子郵件到一個地址和密件抄送2其他地址。它發送給收件人罰款,但我只能讓它發送到2個密送地址之一。 (看代碼中的評論爲什麼試圖)bcc多個地址與swiftmailer
奇怪的是,雖然結果回來3,所以它似乎試圖發送第二封密件抄送電子郵件,但它永遠不會通過。
<?php
$tracker='[email protected]';
$subject = $_POST['subject'];
$sender = $_POST['sender'];
$toEmail=$_POST['toEmail'];
$passedInEmail=stripslashes($_POST['message']);
$passedInEmail=preg_replace('/ /',' ',$passedInEmail);
require_once('swiftLib/simple_html_dom.php');
require_once('swiftLib/swift_required.php');
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
// Create the message
$message = Swift_Message::newInstance();
//turn the meesage into an object using simple_html_dom
//so we can iterate through and embed each image
$content = str_get_html($passedInEmail);
// Retrieve all img src tags and replace them with embedded images
foreach($content->find('img') as $e)
{
if($e->src != "")
{
$value = $e->src;
$newValue = $message->embed(Swift_Image::fromPath($value));
$e->src = $newValue;
}
}
$message->setSubject($subject);
$message->setFrom($sender);
$message->setTo($toEmail);
//this is my problem
$message->setBcc(array('[email protected]',$sender));
//as it is above only "sender" gets the email
//if I change it like this:
//$message->setBcc($tracker,$sender);
//only "tracker" gets the email
//same if I change it like this:
//$message->setBcc($sender);
//$message->addBcc($tracker);
$message->setReplyTo(array('[email protected]'));
$message->setBody($content,'text/html');
$result = $mailer->send($message);
if ($result=3) {
echo 'Email Sent!';
}
else {
echo 'Error!';
}
?>
這樣做的正確方法是什麼?
您是否有使用AddBcc的樂趣? – allen213
嘗試使用一些pnrbuilder.com地址作爲第二封電子郵件。也許這是因爲服務器配置。 – Ziumin
@ allen213 nope addBcc()給出了相同的結果(添加到我的問題上面) – DelightedD0D