1

我已阅读有关此问题的类似帖子,但无法完全理解我在这里做错了什么。收到“收件人”电子邮件正常。

但是,使用以下脚本时,我无法发送“抄送”电子邮件。任何帮助将非常感激。

// Require Pear Mail Packages 
require_once ("Mail.php"); 
require_once ("Mail/mime.php");
require_once ("Mail/mail.php");

$crlf = "\n"; 
$from = "Company <admin@example.com>";
$to =  $purchasersName . "<" . $purchasersEmail . ">";
$cc = "Company <admin@example.com>";
$subject = "Company Order Confirmation";

$host = "localhost";
$port = "25";
$username = "the username";
$password = "the password";

$hdrs = array ('From' => $from,
'To' => $to,
'Cc' => $cc,
'Subject' => $subject);

$mime = new Mail_mime(array('eol' => $crlf));
$mime->setHTMLBody($mailBody);
$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$smtp =& Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $hdrs, $body);
4

1 回答 1

6

此评论在此页面的梨文档中

http://pear.php.net/manual/en/package.mail.mail.send.php

(如果你想要其他选择,你可以试试http://swiftmailer.org,我现在在很多项目中都使用过)

注意:arminfrey@gmail.com 2007-07-08 05:13 UTC 为了使用 smtp 向 cc 或 bcc 发送电子邮件,您必须将 cc 电子邮件地址都列为收件人(这决定了 e -mail 被发送)并在 cc 标头中,它告诉邮件客户端如何显示它。

这是我使用的代码:

$to = 'to@example.com'; $cc = 'cc@example.com';

$recipients = $to.", ".$cc;

$headers['来自'] = '来自@example.com'; $headers['To'] = $to; $headers['Subject'] = '测试消息'; $headers['Cc'] = 'cc@example.com'; $headers['Reply-To'] = 'from@example.com';

$send = $mail->send($recipients, $headers, $body);

于 2013-08-25T23:50:45.540 回答