SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Sending 2 parts of a body with Swiftmailer?

    I have an email that is being sent to users. They receive the mail every time something is happening. Now I'm planning to make something, so that users can select if they only want these emails once a week. Let's say it is like a forum. You write your thing and then you get an email as soon as someone is writing something in your thread.
    But, if you want to get these emails once a week I would like to add them all into one single email.

    So, my plan is to have one header (with my logo, all the info and also an option to read the e-mail in your browser). This part includes a unique code in the browser link (this is for statistics).
    So, Im thinking about making the header as a web page (which is what I use for the regular emails). So there I set up the text and the link to use for reading in the browser. This part I like to include in my email as
    PHP Code:
    $message1 file_get_contents('http://www.webpage.com/newsletter_7_1.php?'.$links); 
    Then I make the same thing with the footer (which includes unique links to unsubscribe and update info). This is also something I like to put on a separate page and import it here as
    PHP Code:
    $message3 file_get_contents('http://www.webpage.com/newsletter_7_3.php?'.$links); 
    Then it's time for the body part. This is built as a web page as well. Every thread looks different. So they have more like a newsletter style.
    I want to include this (with all the links and images and whatever) as
    PHP Code:
    $message2 file_get_contents('http://www.webpage.com/newsletter_7_2.php?'.$links); 
    Then put together all these parts to
    PHP Code:
    $message $message1.$message2.$message3
    But before I do this, I want it to loop in my table to get the correct body parts and put them together one by one until it's time for the final footer.
    So it might be something like this: header,body1,body2,body3,footer. Or if just two things happened the last week: header,body1,body2,footer.

    I have a table with the e-mail and things about every part and if they want an email weekly send_weekly is set to 7.
    So first I select my table to get the stuff:

    PHP Code:
    "SELECT * FROM to_send_table WHERE sent <> 1 AND send_weekly ='7' LIMIT 0,50" 
    But I guess I need to find out the number of body parts the actual user has. But I don't know how to make this work for me.

    This is parts of what I've got:

    PHP Code:
    $to $row['email'];
    $subject $row['subject'];
    //Then I have all the links to the unique codes.

    // And then the Swift mailer parts
    $mailer Swift_Mailer::newInstance($transport); 
    Where do I put the loops? And, should there be a loop inside one loop to first set the header for the user and then a loop selecting all the body parts for the specific user before going to the footer and after that run the loop again to see if there are more users marked with weekly emails?

    I'm just stuck here. But the original emails are working fine.

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    In pseudo code:

    Code:
    users = selectAllUsersThatWantAWeeklyUpdate();
    for (user in users)
    {
        body = 'your email header here'
        threads = selectThreadsRelevantForUserForLastWeek(user)
        for (thread in threads)
        {
             body = body + getEmailSummaryForThread(thread)
        }
        body = body + 'your footer here'
        email = new Email(body)
        email->send(user)
    }
    Very abstract, but it should give you some initial ideas to go by - hopefully
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Maybe I'm too much of a beginner in php, but what are these?
    PHP Code:
    for (user in users
    and
    PHP Code:
    for (thread in threads
    Never seen these in a loop with the word in.

    Will that one count the amount of hits?

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    It's not PHP, it's psuedo code. In PHP it would be foreach ($users as $user) and foreach ($threads as $thread)
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


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
  •