English 中文(简体)
第1个名字领域正在两次插入电子邮件。
原标题:First name field is being inserted into emails twice

I am using the following code to send out emails, the problem I am having is that when I send an email, the persons name is imported just fine as long a the fuel type, but some some reason it seems to be pulling in the $name value twice.

例如,我收到电子邮件,如:

Dear Tom Sawyer Tom Sawyer, 这里是您。 价格:

Dear Will Thompson Will Thompson, 页: 1

Here is a quick explanation of my values : $templatename = the email template, this has stored in it the message to go out to the customer, plus a curly brackets named {name} and another called {fuel}.

{名称}从名称中删除,代之以人名,{燃料}以模板的名称取而代之,模板是使用的燃料名称。 这样做是用地体。

因此,结果应当是Dear, PERSONSnonE, 这里是您的UNEL TYPE价格,但我实际上得到的是,这些人的名字是出于某种原因重复的两度?

              <?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 {text-align:center;font-family:"Times New Roman", Times, serif; font-size:130% !important; font-weight:bold; color:#fff;} .address {color:#fff; font-size:60%; font-family:Verdana, Geneva, sans-serif;}</style>
                              </head>

                              <body>
                              <div style="background:
                                                                none repeat scroll 0% 0% rgb(6, 38,
                                                                97); width:650px; height:auto;">
                              <img id="_x0000_i1030" style="padding-left:5%;padding-right:5%"
                                                                    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 style="background:#344ea2; width:501px; height:65px; margin-left:70px;"></div>

                                                                    <div style="background:#13155C; height:30px; width:501px; margin-left:70px;"></div>

                                                                    <div style="background:#fff; width:501px; height:365px; margin-left:70px;"></div>

<div style="background:
                                                                none repeat scroll 0% 0% rgb(6, 38,
                                                                97); height:60px; width:501px; margin-left:70px;"></div>    

                                                                <div style="background:#000139;height:100px; width:580px; margin-left:35px;" >
                                                                  <table cellspacing="0" cellpadding="0" class="address" style="margin-left:5px;">
                                                                    <tr>
                                                                      <td valign="top" width="21%"><p><strong>Chandlers                                                    Depots</strong></p>
                                                                        <table class="address" border="0" cellpadding="0" cellspacing="0" width="87%">
                                                                          <tbody>
                                                                            <tr>
                                                                              <td width="57%"><p>Grantham</p></td>
                                                                              <td width="43%"><p>Spalding</p></td>
                                                                            </tr>
                                                                            <tr>
                                                                              <td><p>Lincoln</p></td>
                                                                              <td><p>Corby</p></td>
                                                                            </tr>
                                                                            <tr>
                                                                              <td><p> Spilsby</p></td>
                                                                              <td><p>Retford</p></td>
                                                                            </tr>
                                                                          </tbody>
                                                                        </table></td>
                                                                      <td valign="top" width="79%"><p><strong>Address<br />
                                                                        <br />
                                                                      </strong>Chandlers                                                  Oil &amp; Gas, Warren                                                  Way, Alma Park,                                                  Grantham, Lincolnshire,                                                  NG31 9SE<br />
                                                                        <br />
                                                                        <strong>TEL: </strong>08456                                                  202010 <strong>FAX:</strong> 01476                                                  568147 <strong>E-Mail: </strong><a href="mailto:[email protected]">[email protected]</a></p>
                                                                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                                                          <tbody>
                                                                            <tr>
                                                                              <td><p align="right"> </p></td>
                                                                            </tr>
                                                                          </tbody>
                                                                        </table></td>
                                                                    </tr>
                                                                  </table>
                                                                </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;
                   $businessname = $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(array( {name} ,  {fuel} ), array($name, $templatename), $htmlBody);
                      $mailer->isHTML(true);
                      $mailer->AltBody = str_replace(array( {name} ,  {fuel} ), array($name, $templatename), $textBody);
                      $mailer->AddAddress($to_email, $name);
                      $mailer->Subject = "Your Fuel Prices From Chandlers Oil & Gas";
                      $mailer->FromName = "Chandlers Oil & Gas";
                  }
                  else
                  {
                      $mailer->Body = str_replace(array( {name} ,  {fuel} ), array($name, $templatename), $textBody);
                      $mailer->isHTML(false);
                      $mailer->Subject = "Your Fuel Prices From Chandlers Oil & Gas";
                      $mailer->FromName = "Chandlers Oil & Gas";
                          $mailer->AddAddress($to_email, $name);                                  
                  }

                  $mailer->Send();
                  $mailer->ClearAddresses();
                  $mailer->ClearAttachments();
                  $mailer->IsHTML(false);
                  echo "Mail sent to: $name - $to_email<br />";
              }

              ?>
最佳回答

我想在此看到:

                  if(!empty($row->businessname))
                  {
                      $name .=    .$row->leadname;
                  }

意指:

                  if(!empty($row->businessname))
                  {
                      $name .=    .$row->businessname;
                  }

:

简言之,这正在根据预期条件使无法预测的变量趋于一致。

问题回答

Change:

              if(!empty($row->businessname))
              {
                  $name .=    .$row->leadname;
              }

:

              if(!empty($row->businessname))
              {
                  $name .=    .$row->businessname;
              }




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签