Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: Email from DB query

  1. #11
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default

    PHP Code:
    <?php

    //CONNECT TO MYSQL
    $link mysql_connect$mysqladd$mysqluser$mysqlpasstrue ) or die( 'Could not connect to database: ' mysql_error() );

    //CONNECT TO DATABASE
    mysql_select_db$databasename$link ) or die( 'Could not connect to table: ' .
        
    mysql_error() );

    $query "SELECT  *,  DATE_FORMAT(Time_of_Submission, '%Y/%m/%d') FROM jobadd  WHERE Kategori='bygg' AND Time_of_Submission BETWEEN SYSDATE() - INTERVAL 1 DAY AND SYSDATE() AND sent = 0 ORDER BY ID DESC";
    $query2 "SELECT * FROM USERS WHERE Kategori='Bygg & Anläggning'";

    $result mysql_query$query );
    $result2 mysql_query$query2 );

    //the email we are sending from
    $fromemail "no_reply@jobler.se"

    //number of rows returned from our 2 queries
    $link_count mysql_num_rows$result );
    $users_count mysql_num_rows$result2 );

    //check if there is at least 1 link to be sent and at least 1 user to get the email
    if ( $link_count && $users_count )
    {

        
    //we should prepare the message in advance since all the users get the same email
        
    while ( $mailmessage mysql_fetch_assoc$result ) )
        {
            
    $where $mailmessage['where'];
            
    $submitted $mailmessage["Länk"];

            
    // The subject
            
    $subject "Det har kommit in en ny Tjänstförfrågan på Jobler.se som passar er profil (klicka på länken nedan)";


            
    // The message
            
    $message .= $mailmessage['where'] . "  " $mailmessage['Länk'] . "\n";
              
              
    //mark the link as sent
              
    mysql_query("UPDATE jobadd SET sent = '1' WHERE id = '".$mailmessage['id']."'");
        }
        
        
    //now we will send the message to all the users
        
    while ( $users mysql_fetch_assoc$result2 ) ){
            
            
            
    $email $users['email'];
            
            if(
    mail($email$subject$message"From: $fromemail"))
                echo 
    "<b><br>Sent to $email</b><br>Message: $message<hr><br>"
             
        }
    }
    else 

    echo 
    "We are sorry it looks like we have no links to send or no one to send them to!";
    }
    This assumes the newly added row is called sent and the you have a unique key in your jobadd table called id

  2. The Following User Says Thank You to jironimo For This Useful Post:

    PatrikIden (02-02-2012)

  3. #12
    Join Date
    Nov 2011
    Location
    Sweden
    Posts
    36
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    That worked perfectly. Thank you so much for your help. I cant tell you how much it means to me, now i got a fully automatic Job ad system thank's to you'r help. So again i thank you.

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
  •