用PHP PEAR MAIL发送多个CC和BCC [英] Sending multiple CC's and BCCs with PHP PEAR MAIL

查看:174
本文介绍了用PHP PEAR MAIL发送多个CC和BCC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我正在工作的项目,我正在使用Pear的邮件。我需要使用smtp,因为我们需要能够跟踪我们的邮件服务器的一切。在发送公司电子邮件之前,用户需要登录。我不能使用php的邮件功能。



我的问题是,我无法找到网上发送CC和Bcc以及发送多个BCC的文档。这是很容易与php的邮件功能。你所做的就是将它添加到$头变量,如下所示

  $ headers。='Cc:birthdayarchive@example.com' 。 \r\\\
;
$ headers。='Bcc:birthdaycheck@example.com'。 \r\\\
;

这是我使用PEAR的php函数的代码

  function sender_mail($ email,$ subject,$ mailmsg,$ cc,$ bcc){

include(Mail.php) ;
/ *邮件设置收件人,主题等* /

// DEFAULT VALUE OF FROM
$ from =noreply@addata.net;

// GET EMAIL OF USER
$ result = mysql_query(SELECT email,email_pass FROM u_perinfo WHERE user_id ='$ _SESSION [uid]')
or die(抓住您的电子邮件信息时出现错误);
if(mysql_num_rows($ result)> 0){
$ row = mysql_fetch_array($ result);
if($ row [0]!=''){
$ from = $ row [0];
}
$ email_pass = $ row [1];
}

$ recipients =$ email;
$ headers [From] =$ from;
$ headers [To] =$ email;
$ headers [Subject] = $ subject;
$ headers [Cc] =$ cc; //我添加的行,看看它是否工作
$ headers [Bcc] =$ bcc; //我添加的行,看看它是否工作


// $ mailmsg =欢迎来到Addatareference.com!\r\\\
\r\\\
Below是你唯一的登录信息。\r\\\
\r\\\
(请不要共享您的登录信息。)$ accountinfo;
/ * SMTP服务器名称,端口,用户/ passwd * /
$ smtpinfo [host] =smtp.emailsrvr.com;
$ smtpinfo [port] =25;
$ smtpinfo [auth] = true;
$ smtpinfo [username] =$ from;
$ smtpinfo [password] =$ email_pass;
/ *使用Mail :: factory方法* /
$ mail_object =& Mail :: factory(smtp,$ smtpinfo);
/ * Ok发邮件* /
$ mail_object-> send($ recipients,$ headers,$ mailmsg);

}

我一直在试图找到一个解决方案,没有真实的信息回来了我的方式。如果有人可以帮助我,我将不胜感激。

解决方案

你尝试添加多个地址 ?

  $ headers ['Cc'] ='cc@example.com,bb@example.com,dd @ ex。 com公司; 

根据来源的第218行


I have a project that I am working on at my job and I am using Pear's mailing. I need to use smtp because we need to be able to track everything from our mailserver. And users need to be able to log in before sending a company based email. We cannot use php's mail function fo this.

My problem is that I cant find any documentation on the net for sending CC and Bcc as well as sending multiple BCCs. It is very easy to do with php' mail funciton . All you do is add it to the $header variable like so

$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

This is my code for the php function where I use PEAR

function sender_mail($email,$subject,$mailmsg, $cc, $bcc){

    include("Mail.php");
    /* mail setup recipients, subject etc */

    //DEFAULT VALUE OF FROM 
    $from = "noreply@addata.net";

    //GET EMAIL OF USER
    $result = mysql_query("SELECT email, email_pass FROM u_perinfo WHERE user_id = '$_SESSION[uid]'")
    or die("There was an error when grabbing your email information");
    if(mysql_num_rows($result) > 0){
        $row = mysql_fetch_array($result);
        if($row[0] != ''){
            $from = $row[0];
        }
        $email_pass = $row[1];
    }

    $recipients = "$email";
    $headers["From"] = "$from";
    $headers["To"] = "$email";
    $headers["Subject"] = $subject;
    $headers["Cc"] = "$cc";  //Line added by Me to see if it works
    $headers["Bcc"] = "$bcc";  //Line added by Me to see if it works


    //$mailmsg = "Welcome to Addatareference.com! \r\n\r\nBelow is your unique login information.  \r\n\r\n(Please do not share your login information.)$accountinfo";
    /* SMTP server name, port, user/passwd */
    $smtpinfo["host"] = "smtp.emailsrvr.com";
    $smtpinfo["port"] = "25";
    $smtpinfo["auth"] = true;
    $smtpinfo["username"] = "$from";
    $smtpinfo["password"] = "$email_pass";
    /* Create the mail object using the Mail::factory method */
    $mail_object =& Mail::factory("smtp", $smtpinfo);
    /* Ok send mail */
    $mail_object->send($recipients, $headers, $mailmsg);

}

I have been trying to find a solution to this with no real info coming back my way. If someone could help me out with this I would be greatly appreciated.

解决方案

Have you tried to add multiple addresses "," separated?

$headers['Cc'] = 'cc@example.com, bb@example.com, dd@ex.com';

This might work, according to line 218 in the source.

这篇关于用PHP PEAR MAIL发送多个CC和BCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆