duanditang2916 2011-06-24 17:41
浏览 296

PEAR PHP邮件,邮件名称来自发件人

I am using PEAR's smtp mailer in PHP and it is working great with attachments CC and BB as well as multiple recipients. My boss needs the sender to say the name of the sender when it is sent to an email. Our sales reps say that this is a must. I tried to follow the directions but when I use the code below the email wont send. Im guessing that all email types within the mailer have to be written in the same format. For example

 //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";

will produce John Doe <johndoe@gmail.com> for the from variable Whereas the the line $from = "$row[2] <$row[0]>;"; turned to $from = $row[0] will produce just johndoe@gmail.com When doing it with the later (with just the email) it sends the information and works perfectly. When trying to incorporate the name it doesn't work at all. Am I doing something wrong? Any help would be greatly appreciated.

UPDATE: this is my mail code that you asked for

$crlf = "
";
        $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! 

Below is your unique login information.  

(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);
  • 写回答

3条回答 默认 最新

  • doushupu2521 2011-06-24 17:57
    关注

    Add another header:

    $fullName = $row[2];
    $headers["X-Sender"] = "<$fullName>";
    
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行