我正在使用PHP中PEAR的smtp邮件发送器,并且它可以很好地处理附件、抄送和多个收件人。我的老板需要在发送邮件时显示发件人的姓名。我们的销售代表说这是必须的。我尝试按照指示操作,但是当我使用下面的代码时,邮件无法发送。我猜测所有邮件类型在发送器中必须采用相同的格式,例如:
//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";
将会在from变量中产生John Doe <johndoe@gmail.com>
,而行$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);