我有这个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工作?
解决方法:
我假设你正在使用Pear类邮件,如果不是无视.
从链接拉出:
$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.
标签:php,email
来源: https://codeday.me/bug/20190831/1776623.html