我在 PHP 中使用 PEAR 的 smtp 邮件程序,它可以很好地处理附件 CC 和 BB 以及多个收件人。我的老板需要发件人在发送到电子邮件时说出发件人的姓名。我们的销售代表说这是必须的。我尝试按照说明进行操作,但是当我使用下面的代码时,电子邮件不会发送。我猜邮件程序中的所有电子邮件类型都必须以相同的格式编写。例如
//GET EMAIL OF USER
$result = mysql_query("SELECT email, email_pass, fullname 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[2] <$row[0]>";
}
$email_pass = $row[1];
}
if(!empty($additional)){
$email .= ", $additional";
}
$recipients = array();
$headers["Subject"] = $subject;
$headers["From"] = "$from";
$headers["To"] = "$email";
$headers["Cc"] = "$cc";
$headers["Bcc"] = "$bcc";
将为John Doe <johndoe@gmail.com>
from 变量生成而
$from = "$row[2] <$row[0]>;";
转向的$from = $row[0]
行将仅生成johndoe@gmail.com
当使用后者(仅使用电子邮件)执行此操作时,它会发送信息并完美运行。尝试合并名称时,它根本不起作用。难道我做错了什么?任何帮助将不胜感激。
更新:这是您要求的我的邮件代码
$crlf = "\n";
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($mailmsg);
$mime->setHTMLBody($mailmsg); body = $mime->get();
$headers = $mime->headers($headers);
//$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, $body);