Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Phpmailer删除html电子邮件上的名称值,但处理纯文本?_Mysql_Arrays_Phpmailer_Php - Fatal编程技术网

Mysql Phpmailer删除html电子邮件上的名称值,但处理纯文本?

Mysql Phpmailer删除html电子邮件上的名称值,但处理纯文本?,mysql,arrays,phpmailer,php,Mysql,Arrays,Phpmailer,Php,我使用phpmailer发送时事通讯,它似乎可以工作并发送纯文本电子邮件,但由于某些原因,在发送html电子邮件时会删除人员姓名,而纯文本工作正常并显示姓名 当它发送电子邮件时,它会在结果页面上显示这一点,因此它似乎没有得到名称,但我不明白为什么 Mail sent to: - crea@cruiseit.co.uk Mail sent to: Toms Tackle Tom Sawyer - crea@cruiseit.co.uk Mail sent to: - crea2k@o2.co.u

我使用phpmailer发送时事通讯,它似乎可以工作并发送纯文本电子邮件,但由于某些原因,在发送html电子邮件时会删除人员姓名,而纯文本工作正常并显示姓名

当它发送电子邮件时,它会在结果页面上显示这一点,因此它似乎没有得到名称,但我不明白为什么

Mail sent to: - crea@cruiseit.co.uk
 Mail sent to: Toms Tackle Tom Sawyer - crea@cruiseit.co.uk
Mail sent to: - crea2k@o2.co.uk
通过HTML我得到:亲爱的,这是你的{fuel}价格: 通过纯文本,我得到:亲爱的鲍勃,这是你的{fuel}价格:

下面的代码看起来正常吗

              <?php
                  $formid = mysql_real_escape_string($_GET[token]);
                              $templatequery = mysql_query("SELECT * FROM hqfjt_chronoforms_data_addmailinglistmessage WHERE cf_id = '$formid'") or die(mysql_error());
                              $templateData = mysql_fetch_object($templatequery);

                              $gasoiluserTemplate = $templateData->gasoilusers;
                              $dervuserTemplate = $templateData->dervusers;
                              $kerouserTemplate = $templateData->kerousers;
                              $templateMessage = $templateData->mailinglistgroupmessage;
                              $templatename = $templateData->mailinglistgroupname;


                require_once('./send/class.phpmailer.php');

               $mailer= new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

               // Grab the FreakMailer class
                require_once('./send/MailClass.inc');

                // Grab our config settings
                require_once('./send/config.php');

              // Setup body
              $htmlBody = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                              <html xmlns="http://www.w3.org/1999/xhtml">
                              <head>
                              <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                              <style>#title {padding-left:120px;padding-top:10px;font-family:"Times New Roman", Times, serif; font-size:22px; font-weight:bold; color:#fff;}</style>
                              </head>

                              <body>
                              <div style="background:
                                                                none repeat scroll 0% 0% rgb(6, 38,
                                                                97); width:780px;">
                              <img id="_x0000_i1030" style="padding-left:100px;padding-right:100px;"
                                                                    src="http://www.chandlersoil.com/images/newsletter/header.gif"
                                                                    alt="Chandlers Oil and Gas"
                                                                    border="0" height="112"
                                                                    width="580">
                                                                    <div id="title">" . $templateMessage . "</div>

                                                                    </div>
                              </body>
                              </html>
                              ';
               $textBody = "$templateData->mailinglistgroupmessage";

              // instantiate the class
              $mailer = new FreakMailer();

              // Get the user's Email
              $sql = mysql_query("SELECT leadname,businessname,email,mailtype FROM hqfjt_chronoforms_data_addupdatelead WHERE keromailinglist='$kerouserTemplate' AND dervmailinglist='$dervuserTemplate' AND gasoilmailinglist='$gasoiluserTemplate'");

              while($row = mysql_fetch_object($sql))
              {
                  // Send the emails in this loop.
                  $name = $row->leadname;
                   $name = $row->businessname;
                    $to_email = $row->email;
                    $mailtype = $row->mailtype;
                  if(!empty($row->businessname))
                  {
                      $name .= ' '.$row->leadname;
                  }
                  $to_name = $name;
                  if($row->MailType == 'html')
                  {
                      $mailer->Body = str_replace('{name}', $name, $htmlBody);
                      $mailer->IsHTML(true);
                      $mailer->AltBody = str_replace('{name}', $name, $textBody);
                      $mailer->AddAddress($to_email, $name);
                  }
                  else
                  {
                      $mailer->Body = str_replace('{name}', $name, $textBody);
                      $mailer->isHTML(false);
                          $mailer->AddAddress($to_email, $name);
                  }
                  $mailer->Send();
                  $mailer->ClearAddresses();
                  $mailer->ClearAttachments();
                  $mailer->IsHTML(false);
                  echo "Mail sent to: $name - $to_email<br />";
              }

              ?>

您正在混合单引号和双引号。更改此行:

<div id="title">" . $templateMessage . "</div>
“$templateMessage。”

”$模板消息。”
您的代码:

$name = $row->leadname;
$name = $row->businessname;
。。。这让我假设你的变量被覆盖了

这是一个很小的代码部分,如果您在更复杂的代码中遇到它,并且您不知道变量在哪里被修改,您可以使用这个小技巧

class WhereIsThisAltered{
     protected $value;
     function __construct($value){
          $this->value = $value;
     }
     function __toString(){
         return $this->value;
     }
     function __destruct(){
         echo "Instance with value:{$this->value} desctructed";
         debug_print_backtrace();
     }
}

$name = new WhereIsThisAltered($row->leadname);

谢谢你!,我将$name重命名为$businessname,它现在正在工作:-)
class WhereIsThisAltered{
     protected $value;
     function __construct($value){
          $this->value = $value;
     }
     function __toString(){
         return $this->value;
     }
     function __destruct(){
         echo "Instance with value:{$this->value} desctructed";
         debug_print_backtrace();
     }
}

$name = new WhereIsThisAltered($row->leadname);