%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/atv-api/wp-content/themes/atv/inc/controllers/
Upload File :
Create Path :
Current File : /var/www/html/atv-api/wp-content/themes/atv/inc/controllers/mailController.php

<?php 

class Mail {

    public function index($request)
    {
        return self::sendMail($request->get_params(), $request->get_file_params());
    }


    public function sendMail($mailData, $files = false)
    {

        $to = ['info@atvbuggy-dubrovnik.com'];
		#$to = ['bube@digitalpresent.mk'];
        $subject = "New message from website";

        $body = "Hi,<br> You have new message from website<br><br>";
        
        foreach($mailData as $key=>$value){
            $body .= "<b>". str_replace("_"," ",$key) .":</b> ". $value. "<br>";
        }

        $headers = array('Content-Type: text/html; charset=UTF-8','From: <'.$mailData['Email'].'>');
        $headers[] = 'From: '.$mailData['First_name'].' <'.$mailData['Email'].'>';
        $headers[] = 'Content-Type: text/html; charset=UTF-8';
        
        $attachments = [];

        if($files) {
            foreach($files as $file) {
                if(!$file['name']) continue;
                move_uploaded_file($file['tmp_name'], get_template_directory().'/temp_uploads/'.$file['name']);
                $attachments[] = get_template_directory().'/temp_uploads/'.$file['name'];
            }
        }

        if(wp_mail( $to, $subject, $body, $headers, $attachments)) {
            echo wp_json_encode([
                'status' => true,
                'message' => 'Thank you for contacting us!',
            ]);
            foreach($attachments as $attach) {
                unlink($attach);
            }
            die();
        }
        echo wp_json_encode([
            'status' => false,
            'message' => "Something went wrong. Please try again!",
        ]);
        die();
    }    
}

Zerion Mini Shell 1.0