1

I want to receive the file uploaded in my form as an email attachment. At the minute it sends a confirmation email but with no attachment. I think I would need to add it as a string attachment.

e.g When a user applies for a role on my website, I would like to receive the CV ($cv) as an email attachment.

Here's my code so far:

<?php

if (!defined('ABSPATH'))
    exit;

class IWJ_Email {
    public static function get_blogname() {
        return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    }

    static public function send_email($type, $args, $method = '') {

        $emails = self::get_emails($type, $args);
        if($emails){
            $email_queue_types = (array)apply_filters('iwj_email_queue_types', array('new_job', 'alert_job'));
            foreach ($emails as $email){
                if ($email['content'] && $email['recipients'] && $email['subject']) {
                    //add mail queue
                    $from_name = self::get_blogname();
                    $from_address = get_bloginfo('admin_email');

                    $mailqueue =  ($method && $method == 'mailqueue') ? true : ($method == 'direct' ? false : in_array($type, $email_queue_types));
                    do_action('iwj_before_send_email', $email, $mailqueue, $type, $args);
                    if($mailqueue){
                        IWJ_Email_Queue::add($from_name, $from_address, $email['recipients'], $email['subject'], $email['content']);
                    }else{
                        //send directly
                        $headers = array();
                        $headers[] = 'Content-Type: text/html; charset=UTF-8';

                        $headers[] = 'From: ' . $from_name . ' <' . $from_address . '>';
                        if(isset($email['reply_name']) && isset($email['reply_to'])){
                            $headers[] = 'Reply-To: ' . $email['reply_name'] . ' <' . $email['reply_to'] . '>';
                        }elseif(isset($email['reply_to'])){
                            $headers[] = 'Reply-To: <' . $email['reply_to'] . '>';
                        }

                        wp_mail($email['recipients'], $email['subject'], $email['content'], $headers);
                    }
                    do_action('iwj_after_send_email', $email, $mailqueue, $type, $args);
                }
            }
        }
    }

    static public function get_email_new_application_employer($args) {
        $type = 'new_application_employer';
        $enable_email = iwj_option('email_'.$type.'_enable');
        if ($enable_email) {
            $application = $args;
            $job = $application->get_job();
            $job_author = $job->get_author();
            $user = IWJ_User::get_user();
            $user_name = $application->get_full_name();
            $user_email = $application->get_email();

            $recipient = $job->get_email_for_apply();
            $heading = iwj_option('email_' . $type . '_heading');
            $subject = iwj_option('email_' . $type . '_subject');
            $content = iwj_option('email_' . $type . '_content');

            $args = array(
                'job' => $job,
                'job_title' => $job->get_title(),
                'employer' => $job_author,
                'employer_name' => $job_author->get_display_name(),
                'employer_email' => $job_author->get_email(),
                'candidate' => $user,
                'candidate_name' => $user_name,
                'candidate_email' => $user_email,
                'application' => $application,
            );

            $email = array(
                'subject' => $subject,
                'heading' => $heading,
                'content' => $content,
                'recipients' => $recipient,
                'args' => $args,
            );

            return array($email);
        }

        return array();
    }

}

Any help would be really appreciated!

rmiddleton
  • 11
  • 2

0 Answers0