Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7041803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:05:27+00:00 2026-05-28T02:05:27+00:00

I am using phpmailer, and have customised it for my needs. Inside $templatemessage is

  • 0

I am using phpmailer, and have customised it for my needs. Inside $templatemessage is the message to the customer with the fields {name} and {fuel}.

These two fields are replaced with the str_replace function.

Before this problem appeared I just had the str_replace replace the {name} and this worked fine, with the name of the person being imported into that place.
The problem arose when I added the extra str_replace function to replace the {fuel} with the $templatemessage value. What happens now is the {fuel} value is imported, but it seems to be doing something to the {name} function as it no longer imports the name and instead displays only {name} in the emails, where as before I added the {fuel} it worked.
How can I get the two to play nicely with each other ?.

                  <?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:websitesales@chandlersoil.com">websitesales@chandlersoil.com</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('{name}', $name, $htmlBody);
      // the line below is the new one I have added
                      $mailer->Body = str_replace('{fuel}', $templatename, $htmlBody);
                      $mailer->isHTML(true);
                      $mailer->AltBody = str_replace('{name}', $name, $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('{name}', $name, $textBody);
    // the line below is the new one I have added
                       $mailer->Body = str_replace('{fuel}', $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 />";
              }

              ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:05:28+00:00Added an answer on May 28, 2026 at 2:05 am

    I would start by trying this:

    $mailer->Body = str_replace(array('{name}', '{fuel}'), array($name, $templatename), $textBody);
    

    From the docs

    If search and replace are arrays, then str_replace() takes a value
    from each array and uses them to search and replace on subject. If
    replace has fewer values than search, then an empty string is used for
    the rest of replacement values. If search is an array and replace is a
    string, then this replacement string is used for every value of
    search. The converse would not make sense, though.

    If search or replace are arrays, their elements are processed first to
    last.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webpage that sends out emails using phpmailer. I set the host
I have a problem sending plain text emails using PHPMailer. I have text that
I have an email template that is inside a PHP script. I am using
I have a VPS with cPanel and I'm using PHPMailer to send email through
I have a form that im trying to get emailed on submit using PHPmailer.
I am trying to send an email from PHP using PHPmailer() . I have
I am working on a PHP based mailing list using PHPmailer. Currently I have
I have an email, sent by phpmailer using plaintext. When this email is sent
Hay I'm using PHPMailer to send some simple emails, however the function SetFrom() doesn't
I'm using the PHPMailer-Lite class to build an email sending script and I'm not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.