我在PHP中使用PEAR的smtp郵件程序,它的工作很好,附件CC和BB以及多個收件人。當發送給電子郵件時,我的老闆需要發件人說出發件人的姓名。我們的銷售代表表示這是必須的。我試圖按照指示,但是當我使用電子郵件下面的代碼不會發送。我猜在郵件程序中的所有電子郵件類型都必須以相同的格式寫入。例如PEAR PHP郵件名稱來自發件人
//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 <[email protected]>
爲從可變,行 $from = "$row[2] <$row[0]>;";
轉向$from = $row[0]
會產生只是[email protected]
當後來做的(只用電子郵件)發送的信息和完美的作品。試圖合併名稱時,它根本不起作用。難道我做錯了什麼?任何幫助將不勝感激。
UPDATE:這是我的郵件代碼,你問
$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);
這並沒有工作,這是一個猜測或你寫錯了什麼? – Dom
我更新了一點。這適用於我。 –