SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Send Email Script

    Hello all,

    I have a script that sends emails to a list of people, and that works fine. However, I set up a thing where I can type %firstname% and %lastname% and then the script should print the user's name from the MySQL table and send the email. However, it is only printing out the first name of the first record in all the emails. Here is part of the script:
    PHP Code:
    $query mysql_query("SELECT email, firstname, lastname, listID, validated, date, id FROM emails WHERE listID=$listID and validated='1'");

    if(!
    $query) {
    errorMsg("Cannot get emails.");
    print 
    mysql_error();
    } else {

    $do_get mysql_query("SELECT * FROM lists WHERE ID=$listID");
    if(!
    $do_get) {
    errorMsg("Cannot query the database at the current time.");
    } else {
    $done mysql_fetch_array($do_get);
    $listEmail $done["listEmail"];
    $archive $done["archive"];
    $listHeader $done["listHeader"];
    $listFooter $done["listFooter"];
    $listHeader stripslashes($listHeader);
    $listFooter stripslashes($listFooter);

    if(
    $header == "1") {
    $text $listHeader;
    }

    $text .= $messagetext;

    if(
    $footer == "1") {
    $text .= $listFooter;
    }

    // *********** Corbb Note **************

    $text stripslashes($text);
    $subject stripslashes($subject);
    $fromname stripslashes($fromname);

    $text str_replace("%quotes%""\""$text);
    $subject str_replace("%quotes%""\""$subject);
    $fromname str_replace("%quotes%""\""$fromname);

    $subject stripslashes($subject);
    $fromname stripslashes($fromname);
    $text stripslashes($text);

    $headers "From: \"$fromname\" <$fromemail>\n" .
                
    "Reply-To: $fromemail\n";



    $x 1;

    while (
    $do mysql_fetch_array($query)) {
    $address $do["email"];
    $firstname $do["firstname"];
    $lastname $do["lastname"];

    $firstname "$firstname";
    $lastname "$lastname";

    $text str_replace("\r\n""\n"$text);
    $text str_replace("%firstname%""$firstname"$text);
    $text str_replace("%lastname%""$lastname"$text);
    $texts str_replace("<--unsub-->"$path "/entry.php?action=add&listID=" $listID .
    "&email=" $address "&what=unsub"$text);
    $mail_send mail($address,$subject,$texts,$headers); 
    If you are confused, listen to this example. In the MySQL database, table emails, your email address is bob@tom.com and your firstname is Bob and your last name is Tom. Well, when the email is sent, it says, "Hi Corbb!" since my name and email is the first record in teh database.

    Does anybody have any ideas?

    Any help is greatly appreciated.
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Er...what's this do?

    PHP Code:
    $firstname "$firstname";
    $lastname "$lastname"
    However, aside from that, I would take this entire block...

    PHP Code:
    $address $do["email"];
    $firstname $do["firstname"];
    $lastname $do["lastname"]; 
    ...and replace it with this:

    PHP Code:
    extract($do); 
    ...that will automatically turn $do["firstname"] into $firstname, and so on, with all of the variables in the $do[] array. It's a handy function that Freddy introduced me to -- thanks Freddy.
    Last edited by TWTCommish; Jul 22, 2001 at 15:48.

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2000
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Chris,

    Thanks for your reply, but now the mail is not sending, even though it says it is.

    Email me for a copy of the script.

    Send the mail to corbb@justforwebmasters.com?subject=send mail script.
    Corbb O'Connor
    Looking for quality website design or database programming?
    Contact me for more information and a FREE quote!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •