我有这个PHP邮件功能:
if(!function_exists("sendemail"))
{
function sendemail($email_to,$email_from,$email_subject,$email_body,$email_replyto)
{
if(filter_var($email_to, FILTER_VALIDATE_EMAIL))
{
require_once "/usr/local/lib/php/Mail.php";
$from = $email_from;
$to = $email_to;
$subject = $email_subject;
$body = $email_body;
$host = "mail.domain.co.uk";
$username = "sending@domain.co.uk";
$password = "*******";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject,
'Content-type' => 'text/html');
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body, $cc);
}
}
}
我已添加了CC电子邮件地址的功能:
if(!function_exists("sendemail"))
{
function sendemail($email_to,$email_from,$email_subject,$email_body,$email_replyto,$cc)
{
if(filter_var($email_to, FILTER_VALIDATE_EMAIL))
{
require_once "/usr/local/lib/php/Mail.php";
$from = $email_from;
$to = $email_to;
$subject = $email_subject;
$body = $email_body;
$host = "mail.domain.co.uk";
$username = "sending@domain.co.uk";
$password = "*******";
$headers = array ('From' => $from,
'To' => $to,
'Cc' => $cc,
'Subject' => $subject,
'Content-type' => 'text/html');
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body, $cc);
}
}
}
但它似乎只是将CC'd电子邮件地址添加到标题中而不是发送电子邮件。它只将电子邮件发送到$ email_to变量
中的地址我有什么想法让CC工作?
答案 0 :(得分:5)
我假设你正在使用Pear类Mail
,如果没有忽视。
根据此(http://pear.php.net/manual/en/package.mail.mail.send.php#2073),您需要在receipients
和headers
中拥有您想要加入的电子邮件地址。我个人从未使用过此代码,所以我无法证明它是否有效。
这是另一个链接说同样的事情:http://raamdev.com/2008/adding-cc-recipients-with-pear-mail/
从链接中拉出:
$to = 'to@example.com';
$cc = 'cc@example.com';
$recipients = $to.", ".$cc;
$headers['From'] = 'from@example.com';
$headers['To'] = $to;
$headers['Subject'] = 'Test message';
$headers['Cc'] = 'cc@example.com';
$headers['Reply-To'] = 'from@example.com';
$send = $mail->send($recipients, $headers, $body);
另外,如果您根据BCC链接需要它,只需在$recipients
添加电子邮件地址,不要将其添加到$headers
。