【发布时间】:2011-09-12 18:38:16
【问题描述】:
我有一个项目正在我的工作中工作,我正在使用 Pear 的邮件。我需要使用 smtp,因为我们需要能够从我们的邮件服务器跟踪所有内容。并且用户需要能够在发送基于公司的电子邮件之前登录。我们不能为此使用php的邮件功能。
我的问题是我在网上找不到任何用于发送 CC 和 Bcc 以及发送多个 BCC 的文档。用 php 的邮件功能很容易做到。你所做的就是像这样将它添加到 $header 变量中
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
这是我使用 PEAR 的 php 函数的代码
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);
}
我一直在努力寻找解决方案,但没有得到任何真实信息。如果有人可以帮助我解决这个问题,我将不胜感激。
【问题讨论】:
-
不知道您使用的 Mail.php 是什么,但我建议您改用 PHPMailer (phpmailer.worxware.com) 或 Swiftmailer (swiftmailer.org)。
-
您是否尝试将包括密件抄送和抄送地址在内的所有电子邮件地址添加到收件人列表中,然后在标题中指定抄送和密送地址?
-
另外,您是否可以从系统发送邮件。您的主机可能阻塞了 25 端口
-
我很确定@jrod 在这里有答案。将您要发送到的每个地址都放入收件人列表中,并使用标题区分“收件人”、“抄送”和“密送”。
-
似乎是一种非常奇怪的方式来组织地址的选择。我花了很长时间才弄清楚到底发生了什么。我想我可以 rtfm。对对对。