简体   繁体   中英

Uploading a resume and sending an email displaying blank page in codeigniter php

Having a career page where i will be filling the details and attaching the resume and sending an email once the user fills the data along with the resume displaying blank page. Working fine if we are not adding upload resume option.

var $image_path;
var $image_path_url;
function __construct()
{
    parent::__construct();
    $this->image_path =realpath(APPPATH . '..admin/images/blogimages');
    $this->image_path_url = base_url().'admin/images/blogimages/thumbs';
}
function apply($email)
    {

        $name = $this->input->post('fullname');
        $email = $this->input->post('email');
        $phone = $this->input->post('mobilenumber');           

        if ( $_FILES AND $_FILES['image_path']['name'])
            {
                $file_name = $this->do_upload2();
                if(is_array($file_name))
                {
                    $error['imageerror'] = $file_name['error'];
                }
                else
                $data['image_path']=$file_name;
            }
            if(!isset($data['image_path']) && !isset($error['imageerror']))
           $error['imageerror'] ="Please Upload an image";
           if(isset($error))return $error;
        //set to_email id to which you want to receive mails
        $to_email = 'yyyy@gmail.com';

        $config=Array(
        'protocol'=> 'smtp',
        'smtp_host' => 'ssl://smtp.gmail.com', //smtp host name
        'smtp_port' => '465', //smtp port number
        'smtp_user' => 'xxxxx@gmail.com',
        'smtp_pass' => 'PASSWORD123', //$from_email password
        'mailtype' =>'html',
        'newline'  =>"\r\n",
        'crlf' =>"\r\n",
        'charset' => 'iso-8859-1',
        'wordwrap' => TRUE
        );

        $message            = array();    
        $message[] = 'Fullname  :  '.trim($name).' ';
        $message[] = 'Email :  '.trim($email).' ';
        $message[] = 'Mobile :  '.trim($phone).' ';


        //$message = implode(PHP_EOL, $message);
        $message = implode('<br>', $message);
        //send mail
        $this->load->library('email',$config);
        $this->email->from($email);
        $this->email->to($to_email);
        //$list = array();
        $path = set_realpath('admin/images/blogimages/thumbs');

        $this->email->message($message);
        $this->email->attach($path . 'image_path');
        $this->email->set_newline("\r\n");
        $this->email->set_mailtype("html"); 
            if ($this->email->send())
        {
           $this->flash->success('Thank you for applying to this post we will get back to you soon!</div>');
            redirect('apply');
        }
        else
        {
            $this->flash->success('There is error in sending mail! Please try again later');
            redirect('apply');
        }
    }

    function do_upload2() 
{
    $config = array(
        'allowed_types' => 'doc|docx|pdf',
        'upload_path' => $this->image_path,
        'max_size' => 20000,
        'maintain_ratio'=>FALSE

    );
    $this->load->library('upload', $config);
    if(!$this->upload->do_upload('image_path'))
    {
        return $error = array('error' => $this->upload->display_errors());
    }
    else
    {
        $image_data = $this->upload->data();
        $config = array(
        'source_image' => $image_data['full_path'],
        'new_image' =>$this->image_path . '/thumbs',
        'maintain_ratio' => FALSE,
        'width' => 83,
        'height' => 83
        );
        $this->load->library('image_lib', $config);
        $this->image_lib->resize();
        $filename =time().preg_replace('/[^A-Za-z0-9\s.\s-]/', '_', $image_data['file_name']);
        rename($image_data['full_path'],$image_data['file_path'].$filename);
        rename($image_data['file_path'].'thumbs/'.$image_data['file_name'],$image_data['file_path'].'thumbs/'.$filename);
        return $filename;
    }
}

Add these lines for uploading images and files while sending email.

$config2 = array(
         'upload_path'=>'../admin/images/blogimages',
        'allowed_types' => 'pdf|doc|docx',
        'max_size' => 20000,            
        );
        $this->load->library('upload', $config2);
        $this->upload->do_upload('attachment'); 
        $upload_data = $this->upload->data();

        $this->email->attach($upload_data['full_path']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM