English 中文(简体)
每一业务的单一地点价值
原标题:Unset a php value on each run of for each

我的行文如下,即:www.phpmailer,在每次行程结束时,我都想清楚姓名的内容,无论是该名称还是美元加权;[牵头名称],我尝试在文字底部使用不定之处,但这似乎没有效果,我刚刚从3人名单上收到2人,其中2人说是 de的,还有1 dear{姓名},尽管这些接触是所谓的,但还是指的。

            <?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;
                                ?>  
                    <?php
            require_once( ./send/class.phpmailer.php );
            //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

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

            // $body                = file_get_contents( contents.html );

            $body =  <!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">{message}</div>

                                                  </div>
            </body>
            </html>
             ;

                            // $body = preg_replace( /\\/i , $body);

                            $mail->SetFrom( [email protected] ,  Chandlers Oil & Gas );
                            $mail->AddReplyTo( [email protected] ,  Chandlers Oil & Gas );

                            $mail->Subject       = "Your Fuel Prices From Chandlers Oil & Gas";

                            $query  = "SELECT leadname,businessname,email FROM hqfjt_chronoforms_data_addupdatelead WHERE keromailinglist= $kerouserTemplate  AND dervmailinglist= $dervuserTemplate  AND gasoilmailinglist= $gasoiluserTemplate ";
                            $result = mysql_query($query);

                            // Bail out on error 
            if (!$result)  
              { 
                trigger_error("Database error: ".mysql_error()." Query used was: ".htmlentities($query), E_USER_ERROR); 
                die();
               }                                    

            while ($row = mysql_fetch_array ($result)) {
              $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";

               // THIS PULLS THE CLIENTS FIRST NAME OUT ON EACH LOOP
               $firstname = $row["leadname"];

               //THIS PULLS THE CLIENTS BUSSINESS NAME OUT ON EACH LOOP
               $businessname = $row["businessname"];

               // IF THE FIRST NAME FIELD IS BLANK USE THE BUSINESS NAME INSTEAD
               if ($firstname =   )
               {$name = $row["businessname"];}
               else 
               {$name = $row["leadname"];}

               // THIS REPLACES THE {NAME} IN THE PULLED IN TEMPLATE MESSAGE WITH THE CLIENTS NAME DEFINED IN $name
               $body = str_replace( {name} , $name, $body);

               // THIS REPLACES {fuel} IN THE PULLED IN TEMPLATE WITH THE TEMPLATE NAME (WHICH IS THE TYPE OF FUEL)
               $body = str_replace( {fuel} , $templatename, $body); 

               // THIS REPLACES THE {message} IN THE $body ARRAY WITH THE TEMPLATE MESSAGE HELD IN $templateMessage
               $body = str_replace( {message} , $templateMessage, $body);


              $mail->MsgHTML($body);
              $mail->AddAddress($row["email"], $row["leadname"]);




              if(!$mail->Send()) {
                echo "Mailer Error (" . str_replace("@", "&#64;", $row["email"]) .  )   . $mail->ErrorInfo .  <br> ;
              } else {
                echo "Message sent to :" . $row["full_name"] .   (  . str_replace("@", "&#64;", $row["email"]) .  )<br> ;
              }
              // Clear all addresses and attachments for next loop
              $mail->ClearAddresses();
              $mail->ClearAttachments();
              unset ($row[ leadname ]);
                              unset ($name;)
            }
            ?>
问题回答

It looks like you need to copy the contents of body into a new variable within your loop. Currently you re overwriting the variable on the first run, removing the {name} placeholders.

           // THIS REPLACES THE {NAME} IN THE PULLED IN TEMPLATE MESSAGE WITH THE CLIENTS NAME DEFINED IN $name
           $newBody= str_replace( {name} , $name, $body);

           // THIS REPLACES {fuel} IN THE PULLED IN TEMPLATE WITH THE TEMPLATE NAME (WHICH IS THE TYPE OF FUEL)
           $newBody = str_replace( {fuel} , $templatename, $newBody); 

           // THIS REPLACES THE {message} IN THE $body ARRAY WITH THE TEMPLATE MESSAGE HELD IN $templateMessage
           $newBody = str_replace( {message} , $templateMessage, $newBody);


          $mail->MsgHTML($newBody);
          $mail->AddAddress($row["email"], $row["leadname"]);

也可以实际使用阵列。

$newBody = str_replace(array( {name} , {fuel} ),array($name,$fuel),$body);

the ; is in a wrong position. Try unset($name); instead of unset($name;),





相关问题
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 ...

热门标签