duanpin2034 2014-04-11 00:25
浏览 27

Php插入查询和电子邮件附件

hope have some help, cant find the problem, i have a script that basically what it doest is submit candidates CV forms.

When a user fill the form whit his personal information and attached his CV, the form will save the information and the cv path in database and leave the cv in a folder inside of the server, than will send a email to the company that post this job. Everything works fine, but only one problem, and this is the CV, this isnt attaching the CV in the email that is sent to the company.

Could someone take a look to the code?

if(isset($_FILES['files'])){


$errors= array();
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
    $file_name = $key.$_FILES['files']['name'][$key];
    $file_size =$_FILES['files']['size'][$key];
    $file_tmp =$_FILES['files']['tmp_name'][$key];
    $file_type=$_FILES['files']['type'][$key];  



    $random_digit=rand(0000,9999);

    $new_file_name=$random_digit.$file_name;

    if($file_size > 2097152){
        $errors[]='File size must be less than 2 MB';
    }       




    $query2="INSERT into candidates (`firstname`,`lastname`,`mobile`,`email`,`message`,`id_company`,`titulo_anuncio`,`job_type`,`data`,ativo) VALUES('$firstname','$lastname','$mobile','$email_candidate','$message','$id_company','$title_en','$job_type','$data','1'); ";
    mysql_query($query2);
    $user_id = mysql_insert_id();

    $query="INSERT into media (`id_candidate`,`file`,`size`,`type`) VALUES('$user_id','$new_file_name','$file_size','$file_type'); ";
    $to = $email;
    $subject = "Domainname.com | Portal of Jobs - New Candidate";

    $body = "";
    $body .= "Title Job: ";
    $body .= $title_en;
    $body .= "
";
    $body .= "Tel: ";
    $body .= $mobile;
    $body .= "
";
    $body .= "Email: ";
    $body .= $email_candidate;
    $body .= "
";
    $body .= "Message: ";
    $body .= $message;
    $body .= "
";
    $body .= "CV: ";
    $body .= "In Attachement";
    $body .= "
";



    $headers = "From:" . $to;
     if (mail($to, $subject, $body,$headers))


    $desired_dir="candidates_cv";
    if(empty($errors)==true){
        if(is_dir($desired_dir)==false){
            mkdir("$desired_dir", 0700);        // Create directory if it does not exist
        }
        if(is_dir("$desired_dir/".$new_file_name)==false){
            move_uploaded_file($file_tmp,"$desired_dir/".$new_file_name);
        }else{                                  // rename the file if another one exist
            $new_dir="$desired_dir/".$new_file_name.time();
             rename($file_tmp,$new_dir) ;               
        }

     mysql_query($query);           
    }else{
            print_r($errors);
    }
}
if(empty($error)){
    echo "<span style=\"color:green;font-weight:bold;\">Submitted whit Sucess Thanks</span>";

}
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)