So, i'm making a newsletter mailer for a small company, they sign up with name and email.. it gets stored in database .. then I made a admin page, an option is to send out an email or newsletter whatever, when you hit send it should send the email to everyone on the database starting with therename EX:

Matthew,

email goes here blah blah blah


so I got it so it emails to every one just cant get the name to show up.. any help would be great, here is the code for reference:

<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$db_data = mysql_query("SELECT first, email FROM contacts");
$subject = 'Urbanformula Newsletter';
$body = $_POST['content'];
$from = "From: \"Urbanformula.com\"";

while ($currRow = mysql_fetch_array($db_data)) {
mail($currRow[1], $subject, $name, $body, $from);
}
?>

any help with this would be great

    What is the content? Is it a pre-formatted file or text?

      Give this a shot:

      <?
      include("dbinfo.inc.php");
      mysql_connect(localhost,$username,$password);
      @mysql_select_db($database) or die( "Unable to select database"); 
      
      //
      // First, you need to return the person's NAME in the query.
      // Question, what is the field first?
      //
      $db_data = mysql_query("SELECT first, name, email FROM contacts");
      
      $subject = 'Urbanformula Newsletter';
      $body = $_POST['content'];
      $from = "From: \"Urbanformula.com\"";
      
      //
      // Second, you need to include it in the list function
      // making sure you keep the field names in the same order as
      // in the select statement in your query
      // 
      while (list($first, $name, $email) = mysql_fetch_row($db_data)) { 
        //
        // Here is where you will be changing the name
        // %name% is a "placeholder" in your pre-formatted
        // message body where you want to put the person's name
        //
        // Here is a sample:
        //
        // Dear %name%,
        //
        //  Here is a copy of the current newsletter.
        //
        //
        // Regards,
        // Newletter Sender
        //
        str_replace('%name%', $name, $body);
      
        //
        // create full email address i.e.
        // "Joe Something" <joesomething@somewhere.com>
        //
        $email = '"'.$name.'"'." <".$email.">";
      
        //
        // mail function parameters are in this order:
        // $to, $subject, $message, $headers
        //
        mail($email, $subject, $body, $from);
      } 
      ?>
      

      Any more questions, just ask.

        Another note, MAKE SURE you have a valid FROM or many email systems will reject it
        as SPAM.
        Your example would be rejected by a lot of systems.

          Do you still see from the code I posted, how to do it?

            here's what i did to fisx the extra id

            <?
            include("dbinfo.inc.php");
            mysql_connect(localhost,$username,$password);
            @mysql_select_db($database) or die( "Unable to select database");

            //
            // First, you need to return the person's NAME in the query.
            // Question, what is the field first?
            //
            $db_data = mysql_query("SELECT first, email FROM contacts");

            $subject = 'Urbanformula Newsletter';
            $body = $_POST['content'];
            $from = "From: \"Urbanformula.com\"";

            //
            // Second, you need to include it in the list function
            // making sure you keep the field names in the same order as
            // in the select statement in your query
            //
            while (list($first, $email) = mysql_fetch_row($db_data)) {
            //
            // Here is where you will be changing the name
            // %name% is a "placeholder" in your pre-formatted
            // message body where you want to put the person's name
            //
            // Here is a sample:
            //
            // Dear %first%,
            //
            // Here is a copy of the current newsletter.
            //
            //
            // Regards,
            // Newletter Sender
            //
            str_replace('%first%', $body);

            //
            // create full email address i.e.
            // "Joe Something" <joesomething@somewhere.com>
            //
            $email = '"'.$first.'"'." <".$email.">";

            //
            // mail function parameters are in this order:
            // $to, $subject, $message, $headers
            //
            mail($email, $subject, $body, $from);
            }
            ?>

            having problem on line 37

              urbanformula wrote:

              line 37 is
              str_replace('%first%', $body);

              Should be:

              str_replace('%first%', $first, $body);

                the mail send ok, but all i get is

                Dear %first%,

                my message

                  Try this.

                  Comment out his line:
                  mail($email, $subject, $body, $from);

                  and add this:
                  echo $body."\n\n";

                  above and below this line:
                  str_replace('%first%', $first, $body);

                  This will show the contents of the body before AND after the str_replace.

                    Hmmm, I wonder if the use of single quotes is causing the str_replace to not work correctly?

                    After that test, try rewriting the str_replace like this:
                    str_replace("%first%", $first, $body);

                      sends it but no name.. just the %first% in the mail.. i'm writing the news letter on a single multiline text field, and the "dear %first%, " is predefined, not sure if thats something

                        Write a Reply...