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

时间:2021-10-27 07:17:27

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

我在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";

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.

将为from变量生成John Doe ,而行$ from =“$ row [2] <$ row [0]>;”;转到$ from = $ row [0]将只生成johndoe@gmail.com当使用后者(仅使用电子邮件)时,它会发送信息并完美运行。当试图合并名称时,它根本不起作用。难道我做错了什么?任何帮助将不胜感激。 @gmail.com>

UPDATE: this is my mail code that you asked for

更新:这是您要求的邮件代码

$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);

3 个解决方案

#1


2  

You should Use

你应该使用

$from = $row[2]." <".$row[0]."> ";

instead

$from = "$row[2] <$row[0]>;";

Also It can be problem with double semicolon. Use only one semicolon at the end.

它也可能是双分号的问题。最后只使用一个分号。

#2


2  

My problem was, that the name should be quoted as the following:

我的问题是,该名称应引用如下:

$from = '"Mywebsite.com" <noreply@mywebsite.com>';

if NAME contains ()<>@,;\:". the string should be quoted

如果NAME包含()<> @,; \:“。应该引用该字符串

Hope it helps someone ;)

希望它可以帮助某人;)

#3


0  

Add another header:

添加另一个标题:

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

#1


2  

You should Use

你应该使用

$from = $row[2]." <".$row[0]."> ";

instead

$from = "$row[2] <$row[0]>;";

Also It can be problem with double semicolon. Use only one semicolon at the end.

它也可能是双分号的问题。最后只使用一个分号。

#2


2  

My problem was, that the name should be quoted as the following:

我的问题是,该名称应引用如下:

$from = '"Mywebsite.com" <noreply@mywebsite.com>';

if NAME contains ()<>@,;\:". the string should be quoted

如果NAME包含()<> @,; \:“。应该引用该字符串

Hope it helps someone ;)

希望它可以帮助某人;)

#3


0  

Add another header:

添加另一个标题:

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