我需要通过一周的技巧向求职者发送工作推荐邮件,它看起来像是一个timejob模板,就像10个推荐的工作对我的技能,我写下面的代码,但我可以得到10个工作通过10封电子邮件不在同一封电子邮件中,我的代码有什么问题?任何人都可以帮助我吗?
<?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="renuka@osiztechnologies.com";
$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);
}
?>
上面只是我试过的一个例子
答案 0 :(得分:2)
如果您收到10封电子邮件而不是1封电子邮件,那么您的mail()函数位于foreach()循环内,而不是while()循环中。从这里更改代码的底部:
$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);
}
......对此:
}
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);
}
}
此外,正如已经在评论中提到的那样,不推荐使用mysql_函数,并且最终将完全从PHP代码库中删除。您应该切换到查询的mysqli或PDO接口,以确保您的代码在将来的PHP更新中不会中断。
答案 1 :(得分:1)
请使用内部联接或左联接,因为当您执行此类操作时,记录不会重复
答案 2 :(得分:0)
您没有在工作表查询中提及任何where子句:
$sel_cron=mysql_query("SELECT * FROM jobs WHERE `postdate` BETWEEN DATE_SUB( NOW( ) , INTERVAL 7 DAY ) AND NOW( ) ") or die(mysql_error());
我认为根据工作技能应该有某种类型的where子句