+ Reply to Thread
Results 1 to 2 of 2

Thread: Newsletter PHP Function - How to rip database emails?

  1. #1
    disturbedart is offline x10 Lieutenant disturbedart is an unknown quantity at this point
    Join Date
    Jun 2006
    Location
    Swindon
    Posts
    458

    Newsletter PHP Function - How to rip database emails?

    I have been creating a newsletter function in my CMS but not to sure on how to select each email from the database to send the email out. Each one needs to be sent individually so the "to" does not display everyones email in one big list. Should send out each individual

    Any Ideas?


    PHP Code:
    <?php
    // Created by Black Nova Designs
    // Connects to your Database 
    $sqlCommand "SELECT email FROM mailinglist"
    $query mysqli_query($connect$sqlCommand) or die (mysqli_error($myConnection)); 

    while (
    $row mysqli_fetch_array($query)) { 

    $query "SELECT email FROM mailinglist";

    $to $row['email'];
    $email   "no-reply@blacknovadesigns.co.uk";
    $name    "Black Nova Designs";
    $subject $_POST['subject'];
    $comment $_POST['message'];

    $To          strip_tags($to);
    $TextMessage =strip_tags(nl2br($comment),"<br>");
    $HTMLMessage =nl2br($comment);
    $FromName    =strip_tags($name);
    $FromEmail   =strip_tags($email);
    $Subject     =strip_tags($subject);

    $boundary1   =rand(0,9)."-"
    .rand(10000000000,9999999999)."-"
    .rand(10000000000,9999999999)."=:"
    .rand(10000,99999);
    $boundary2   =rand(0,9)."-".rand(10000000000,9999999999)."-"
    .rand(10000000000,9999999999)."=:"
    .rand(10000,99999);

     
    for(
    $i=0$i count($_FILES['youfile']['name']); $i++){
    if(
    is_uploaded_file($_FILES['fileatt']['tmp_name'][$i]) &&
       !empty(
    $_FILES['fileatt']['size'][$i]) &&
       !empty(
    $_FILES['fileatt']['name'][$i])){
        
    $attach      ='yes';
    $end         ='';

       
    $handle      =fopen($_FILES['fileatt']['tmp_name'][$i], 'rb');
       
    $f_contents  =fread($handle$_FILES['fileatt']['size'][$i]);
       
    $attachment[]=chunk_split(base64_encode($f_contents));
       
    fclose($handle);

    $ftype[]       =$_FILES['fileatt']['type'][$i];
    $fname[]       =$_FILES['fileatt']['name'][$i];
    }
    }

    /***************************************************************
     Creating Email: Headers, BODY
     1- HTML Email WIthout Attachment!! <<-------- H T M L ---------
     ***************************************************************/
    #---->Headers Part
    $Headers     =<<<AKAM
    From: $FromName <$FromEmail>
    Reply-To: 
    $FromEmail
    MIME-Version: 1.0
    Content-Type: multipart/alternative;
        boundary="
    $boundary1"
    AKAM;

    #---->BODY Part
    $Body        =<<<AKAM
    MIME-Version: 1.0
    Content-Type: multipart/alternative;
        boundary="
    $boundary1"

    This is a multi-part message in MIME format.

    --
    $boundary1
    Content-Type: text/plain;
        charset="windows-1256"
    Content-Transfer-Encoding: quoted-printable

    $TextMessage
    --
    $boundary1
    Content-Type: text/html;
        charset="windows-1256"
    Content-Transfer-Encoding: quoted-printable

    $HTMLMessage

    --
    $boundary1--
    AKAM;

    /***************************************************************
     2- HTML Email WIth Multiple Attachment <<----- Attachment ------
     ***************************************************************/
     
    if($attach=='yes') {

    $attachments='';
    $Headers     =<<<AKAM
    From: $FromName <$FromEmail>
    Reply-To: 
    $FromEmail
    MIME-Version: 1.0
    Content-Type: multipart/mixed;
        boundary="
    $boundary1"
    AKAM;

    for(
    $j=0;$j<count($ftype); $j++){
    $attachments.=<<<ATTA
    --$boundary1
    Content-Type: 
    $ftype[$j];
        name="
    $fname[$i]"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment;
        filename="
    $fname[$j]"

    $attachment[$j]

    ATTA;
    }

    $Body        =<<<AKAM
    This is a multi-part message in MIME format.

    --
    $boundary1
    Content-Type: multipart/alternative;
        boundary="
    $boundary2"

    --
    $boundary2
    Content-Type: text/plain;
        charset="windows-1256"
    Content-Transfer-Encoding: quoted-printable

    $TextMessage
    --
    $boundary2
    Content-Type: text/html;
        charset="windows-1256"
    Content-Transfer-Encoding: quoted-printable

    $HTMLMessage

    --
    $boundary2--

    $attachments
    --
    $boundary1--
    AKAM;
    }

    /***************************************************************
     Sending Email
     ***************************************************************/
    $ok=mail($To$Subject$Body$Headers);
    echo 
    $ok?"<h1> Mail Sent to " $to "</h1>":"<h1> Mail did not SEND to " $to "</h1>";
    }
    }
    ?>


    ---------- Post added at 03:09 PM ---------- Previous post was at 02:50 PM ----------

    with this code i have got it to send to the first row but i need it to send to all rows.


    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    ini_set('display_errors'1);
    ?>

    <?php
    // Created by Black Nova Designs
    // Connects to your Database
    require_once "../../../administrator/dbc.php";
    $sqlCommand "SELECT email FROM mailinglist";
    $query mysqli_query($myConnection$sqlCommand) or die (mysqli_error($myConnection));
    while (
    $row mysqli_fetch_array($query)) {

    $query "SELECT email FROM mailinglist";

    $to $row['email'];
    $email   "no-reply@blacknovadesigns.co.uk";
    $name    "Black Nova Designs";
    $subject $_POST['subject'];
    $comment $_POST['message'];

    $To          strip_tags($to);
    $TextMessage =strip_tags(nl2br($comment),"<br>");
    $HTMLMessage =nl2br($comment);
    $FromName    =strip_tags($name);
    $FromEmail   =strip_tags($email);
    $Subject     =strip_tags($subject);

    $boundary1   =rand(0,9)."-"
    .rand(10000000000,9999999999)."-"
    .rand(10000000000,9999999999)."=:"
    .rand(10000,99999);
    $boundary2   =rand(0,9)."-".rand(10000000000,9999999999)."-"
    .rand(10000000000,9999999999)."=:"
    .rand(10000,99999);

     
    for(
    $i=0$i count($_FILES['youfile']['name']); $i++){
    if(
    is_uploaded_file($_FILES['fileatt']['tmp_name'][$i]) &&
       !empty(
    $_FILES['fileatt']['size'][$i]) &&
       !empty(
    $_FILES['fileatt']['name'][$i])){
        
    $attach      ='yes';
    $end         ='';

       
    $handle      =fopen($_FILES['fileatt']['tmp_name'][$i], 'rb');
       
    $f_contents  =fread($handle$_FILES['fileatt']['size'][$i]);
       
    $attachment[]=chunk_split(base64_encode($f_contents));
       
    fclose($handle);

    $ftype[]       =$_FILES['fileatt']['type'][$i];
    $fname[]       =$_FILES['fileatt']['name'][$i];
    }
    }

    /***************************************************************
     Creating Email: Headers, BODY
     1- HTML Email WIthout Attachment!! <<-------- H T M L ---------
     ***************************************************************/
    #---->Headers Part
    $Headers     =<<<AKAM
    From: $FromName <$FromEmail>
    Reply-To: 
    $FromEmail
    MIME-Version: 1.0
    Content-Type: multipart/alternative;
        boundary="
    $boundary1"
    AKAM;

    #---->BODY Part
    $Body        =<<<AKAM
    MIME-Version: 1.0
    Content-Type: multipart/alternative;
        boundary="
    $boundary1"

    This is a multi-part message in MIME format.

    --
    $boundary1
    Content-Type: text/plain;
        charset="windows-1256"
    Content-Transfer-Encoding: quoted-printable

    $TextMessage
    --
    $boundary1
    Content-Type: text/html;
        charset="windows-1256"
    Content-Transfer-Encoding: quoted-printable

    $HTMLMessage

    --
    $boundary1--
    AKAM;

    /***************************************************************
     2- HTML Email WIth Multiple Attachment <<----- Attachment ------
     ***************************************************************/
     
    if($attach=='yes') {

    $attachments='';
    $Headers     =<<<AKAM
    From: $FromName <$FromEmail>
    Reply-To: 
    $FromEmail
    MIME-Version: 1.0
    Content-Type: multipart/mixed;
        boundary="
    $boundary1"
    AKAM;

    for(
    $j=0;$j<count($ftype); $j++){
    $attachments.=<<<ATTA
    --$boundary1
    Content-Type: 
    $ftype[$j];
        name="
    $fname[$i]"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment;
        filename="
    $fname[$j]"

    $attachment[$j]

    ATTA;
    }

    $Body        =<<<AKAM
    This is a multi-part message in MIME format.

    --
    $boundary1
    Content-Type: multipart/alternative;
        boundary="
    $boundary2"

    --
    $boundary2
    Content-Type: text/plain;
        charset="windows-1256"
    Content-Transfer-Encoding: quoted-printable

    $TextMessage
    --
    $boundary2
    Content-Type: text/html;
        charset="windows-1256"
    Content-Transfer-Encoding: quoted-printable

    $HTMLMessage

    --
    $boundary2--

    $attachments
    --
    $boundary1--
    AKAM;
    }

    /***************************************************************
     Sending Email
     ***************************************************************/
    $ok=mail($To$Subject$Body$Headers);
    echo 
    $ok?"<h1> Mail Sent to " $to "</h1>":"<h1> Mail did not SEND to " $to "</h1>";
    }

    ?>


    ---------- Post added at 03:19 PM ---------- Previous post was at 03:09 PM ----------

    Never Mind i have completed this and is now working.
    Thanks,
    Close Thred.
    Free Professional Webdesigns!

    Check it out!
    .................................................. ......................

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Newsletter PHP Function - How to rip database emails?

    Read over the X10 Acceptable Use Policy to make sure you're not violating it when sending bulk e-mail. If you're uncertain, start a new thread in the "Free Hosting" forum or ask in IRC.

    You can send to multiple addresses with a single call to mail without each recipient seeing the others' addresses by using the bcc header.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 11-02-2011, 09:46 AM
  2. PHP mail function - not sending emails
    By hortacristian21 in forum Free Hosting
    Replies: 1
    Last Post: 07-21-2011, 06:17 AM
  3. Newsletter
    By quadrant in forum Programming Help
    Replies: 2
    Last Post: 04-19-2008, 07:54 PM
  4. newsletter
    By swirly in forum Off Topic
    Replies: 3
    Last Post: 11-09-2006, 06:04 AM
  5. Server Update emails/Latest news Emails
    By Cycloneflame in forum Feedback and Suggestions
    Replies: 2
    Last Post: 04-30-2005, 10:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers