1

i need to send a job recommendation mail to the jobseekers by skill by a week , it would be look like a timesjob template, like 10 recommended jobs to my skill, i write the code like below , but i can get 10 jobs by 10 emails not in the same email , what is wrong with my code? can any one help to me?

    <?php
    $today_date=date("Y-m-d");

/* jobs     
   key_skills
   id
   postdate
   reference_no
   company_id
   designation
   locations
   qualification
   industry
   job_type
   job_timing
   expr_min
   min_expmon
   expr_max
   max_expmon
   compensation_lacs
   compensation_thousand
   description
   cr_dt
   status
   interview_date
   intw_time
   intw_exptime
   t_status
   website    
 */
  //  AND j.key_skills  like '%".$get_singlekeyskill[$i_key]."%'


  "SELECT 
    j.id, 
    j.user_id, 
    j.first_name, 
    j.last_name, 
    j.mobile_no, 
    j.experience_years, 
    j.experience_months, 
    j.annual_salary_lacs, 
    j.annual_salary_thousan, 
    j.functional_type, 
    j.key_skills, 
    j.prefered_cityname, 
    j.basic_qualification, 
    j.post_qualification, 
    c.category_id, 
    c.category_name, 
    d.degree_id, 
    d.degree_name, 
    u.user_email 
FROM 
    users as u, 
    job_seeker as j, 
    category as c, 
    degree as d 
WHERE 
    c.category_id = j.functional_type 
AND 
    d.degree_id=j.basic_qualification 
AND 
    j.user_id=u.id"

$check_searching_query = mysql_query() or die (mysql_error()); 

$numtest_rows=mysql_num_rows($check_searching_query);     

    /* $fetch_allqry=mysql_fetch_array($check_searching_query);   */    

if($numtest_rows>0)
{ 
    while( $fetch_allqry=mysql_fetch_array($check_searching_query))
    {           
        $getjobseeker_id=$fetch_allqry['user_id'];      

        $get_usermailid=$fetch_allqry['user_email'];   



        $get_userfirstname=$fetch_allqry['first_name'];
        $get_usermobileno=$fetch_allqry['mobile_no'];
        $get_userexpyr=$fetch_allqry['experience_years'];
        $get_userexpmonth=$fetch_allqry['experience_months']; 
        $get_usersallac=$fetch_allqry['annual_salary_lacs'];
        $get_usersalthous=$fetch_allqry['annual_salary_thousan'];
        $get_userfuncttype=$fetch_allqry['category_name'];
        $get_userskill=$fetch_allqry['key_skills'];
        $get_userpreferedcityname=$fetch_allqry['prefered_cityname'];
        $get_userqual=$fetch_allqry['degree_name'];
        $get_singlekeyskill=explode(",",$get_userskill);    

        foreach($get_singlekeyskill as $get_userskill) {   

            /*
                job_seeker
                d
                user_id
                first_name
                last_name
                fathers_name
                dob
                gender
                marital_status
                country_id
                state_id
                city_name
                mobile_no
                tel_country_code
                tel_city_code
                phone_no
                experience_years
                experience_months
                annual_salary_lacs
                annual_salary_thousan
                functional_type
                industry_type
                key_skills
                resume_title
                prefered_city_id
                prefered_cityname
                basic_qualification
                post_qualification
                functional_type
                industry_type
                */

                /*
                category
                category_id
                category_name     
                */

                 /*
                    degree
                    degree_id
                    degree_name
                */

                  $sel_cron=mysql_query("SELECT * FROM jobs WHERE `postdate` BETWEEN DATE_SUB( NOW( ) , INTERVAL 7 DAY ) AND NOW( )  ") or die(mysql_error());  
                  $fet_cr=mysql_fetch_assoc($sel_cron) ;   

                  while($fet_cr=mysql_fetch_array($sel_cron))                     
                  {    
                    $db_job_id=$fet_cr['id'];     
                    $db_jpostdate=$fet_cr['postdate'];    
                    $num_empid=$fet_cr['company_id'];  
                    $sel_companname=mysql_query("select * from employer where `user_id`='$num_empid' ") or die(mysql_error());   
                    $fetch_companname=mysql_fetch_array($sel_companname);
                    $emp_companyname=$fetch_companname['company_name'];
                    $db_keyskill=$fet_cr['key_skills'];   
                    $db_minyear=$fet_cr['expr_min'];   
                    $db_minmon=$fet_cr['min_expmon'];   
                    $db_maxyear=$fet_cr['expr_max'];   
                    $db_maxmon=$fet_cr['max_expmon'];        
                    $db_locations=$fet_cr['locations'];             
                    $db_job_timing=$fet_cr['job_timing'];   
                    $db_designation=$fet_cr['designation'];   
                    $db_description=$fet_cr['description'];     
                    $db_interviewdate=$fet_cr['interview_date'];            
                    $db_complac=$fet_cr['compensation_lacs'];   
                    $db_compthousand=$fet_cr['compensation_thousand'];     

                    /*
                        $overall_arr[]=array($db_job_id,
                                    $db_jpostdate,
                                    $num_empid,
                                    $db_keyskill,
                                    $db_minyear,
                                    $db_minmon,
                                    $db_maxyear,
                                    $db_maxmon,
                                    $db_designation,
                                    $db_description,
                                    $db_interviewdate
                        );
                    */
                 }

                 $admin_emialid="[email protected]";

                 $content_pop="hfkhkdhfdjfjgdfjgdjgfjgdjfgjdgfj dvfdfhdgfhdgfsdgfhjdfh dhfgdhgfdjfg   " . $db_job_id;
                 $subj="Recoomended mail";

                 $headers1 = "From: JOBSITE \r\n";
                 $headers1 .= "Reply-To: ".$admin_emialid. "\r\n";
                 $headers1 .= "MIME-Version: 1.0\r\n";

                 $headers1 .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        }
    }
    mail($get_usermailid,$subj, $content_pop,$headers1);
}
?>

The above is just a example one I tried

2
  • 1
    It's really hard to read your code because the indentation is all weird and inconsistent. Can you fix that? Commented Mar 1, 2013 at 14:43
  • 6
    off topic: Be aware that the mysql_xx() functions are deprecated. It is strongly recommended to switch to the alternative mysqli or PDO libraries. Commented Mar 1, 2013 at 14:47

3 Answers 3

2

If you're getting 10 emails instead of 1, then your mail() function is inside the foreach() loop rather than the while() loop. Change the bottom of your code from this:

            $subj="Recoomended mail";
            $headers1 = "From: JOBSITE \r\n";
            $headers1 .= "Reply-To: ".$admin_emialid. "\r\n";
            $headers1 .= "MIME-Version: 1.0\r\n";
            $headers1 .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        }
    }
    mail($get_usermailid,$subj, $content_pop,$headers1);
}

...to this:

        }
        subj="Recommended mail";
        $headers1 = "From: JOBSITE \r\n";
        $headers1 .= "Reply-To: ".$admin_emialid. "\r\n";
        $headers1 .= "MIME-Version: 1.0\r\n";
        $headers1 .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        mail($get_usermailid,$subj, $content_pop,$headers1);
    }
}

Also, as has been mentioned in a comment already, mysql_ functions are deprecated and will eventually be removed from the PHP codebase entirely. You should switch to mysqli or a PDO interface for your queries, to make sure your code doesn't break in a future PHP update.

Sign up to request clarification or add additional context in comments.

Comments

1

Kindly use inner join or left join as records are not duplicated when you do things like this

Comments

0

You did not mention any where clause in your job table query:

 $sel_cron=mysql_query("SELECT * FROM jobs WHERE `postdate` BETWEEN DATE_SUB( NOW( ) , INTERVAL 7 DAY ) AND NOW( )  ") or die(mysql_error()); 

I think there should be some type of where clause needed according to job skill

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.