2014-02-28 81 views
0

我真的爲這個班而苦惱。我送郵件是這樣的:PHP郵件忽略密件抄送

try { 
    // minimal requirements to be set 
    $dummy = new Mailer(); 
    $dummy->setFrom("MAIL SCRIPT", "[email protected]"); 
    $dummy->addRecipient($naam, $email); 
    $dummy->fillSubject("Jouw ruiling #" . $_GET['id']); 
    $dummy->addCCO("Testuser1", "[email protected]"); 
    $dummy->addCCO("Testuser2", "[email protected]"); 
    $dummy->fillMessage($myMessage); 

    // now we send it! 
    $dummy->send(); 
} catch (Exception $e) { 
    echo $e->getMessage(); 
    exit(0); 
} 

這是我send()功能和我packheader()功能:

public function send() { 
    if (is_null($this->to)) { 
     throw new Exception("Must have at least one recipient."); 
    } 

    if (is_null($this->from)) { 
     throw new Exception("Must have one, and only one sender set."); 
    } 

    if (is_null($this->subject)) { 
     throw new Exception("Subject is empty."); 
    } 

    if (is_null($this->textMessage)) { 
     throw new Exception("Message is empty."); 
    } 

    $this->packHeaders(); 

    $sent = mail($this->to, $this->subject, $this->textMessage, $this->headers); 
    if(!$sent) { 
     $errorMessage = "Server couldn't send the email."; 
     throw new Exception($errorMessage); 
    } else { 
     return true; 
    } 
} 


private function packHeaders() { 
    if (!$this->headers) { 
     $this->headers = "MIME-Version: 1.0" . PHP_EOL; 
     $this->headers .= "Content-Type: text/html; charset=\"utf-8\"" . PHP_EOL; 
     $this->headers .= "Content-Transfer-Encoding: 7bit"; 
     $this->headers .= "From: " . $this->from . PHP_EOL; 
     $this->headers .= "Bcc: " . $this->cco . PHP_EOL; 

     if (self::STRIP_RETURN_PATH !== TRUE) { 
      $this->headers .= "Reply-To: " . $this->replyTo . PHP_EOL; 
      $this->headers .= "Return-Path: " . $this->from . PHP_EOL; 
     } 
    } 
} 

在這裏,我加入了CCO/BCC:

public function addCCO($name, $address) { 
    $this->cco .= (is_null($this->cco)) ? ("$name <$address>") : (", " . "$name <$address>"); 
    return $this; 
} 

發送的郵件包含正文中的BCC名稱,而不是標題中。有沒有人看到這個問題?郵件正確發送到$naam$email,只有BCC無法正常工作。

回答

2

你錯過了這裏附加EOL

$this->headers .= "Content-Transfer-Encoding: 7bit" . PHP_EOL; 
               // ^Here 
+0

有時,最簡單的事情,讓我們奮鬥了很長時間。那很簡單!謝了哥們。 –

相關問題