HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux Bradford-Sitios 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: www-data (33)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/gestor-horarios.bradford/app/helpers/sendgrid_helper.php
<?php 

require_once ('sendgrid-php/sendgrid-php.php');

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//https://sendgrid.api-docs.io/v3.0/contacts-api-segments/create-a-segment

use SendGrid\Mail\Mail;

function sendEmail($email_data = '')
{
	// ENVIO MAIL SENDGRID

	$email_data['remitente'] = "contacto@automata.cl";
	$email_data['usuario']   = "Evaluación de desempeño - Grupo automata";

	
	$destinatario = $email_data['destinatario'];		
	$remitente = $email_data['remitente'];
	$usuario = $email_data['usuario'];
	$asunto = $email_data['asunto'];
	$mensaje = $email_data['mensaje'];

	$email = new Mail();
	try {
		$email->setFrom($remitente, $usuario);
		$email->setSubject($asunto);
		$email->addTo($destinatario, "");
	} catch (Exception $e) {
		//return $e;
		return 0;
	}
	if (!empty($email_data['ruta_file'])) {
		$adjunto = file_get_contents(UPLOAD_PATH . $email_data['ruta_file'] . $email_data['name_file']);
		if ($adjunto) {
			$email->addAttachment($adjunto, 'application/pdf', !empty($email_data['name_file_mail']) ? $email_data['name_file_mail'] : $email_data['name_file']);
		} else {
			
		}
	}
	$email->addContent(
		"text/html", $mensaje
	);

	$sendgrid = new \SendGrid(SENDGRID_API_KEY);
	$message_id = 0;
	try {
		$response = $sendgrid->send($email);
		$array_headers = $response->headers();
		
		foreach ($array_headers as $header) {
			if (strpos($header, 'X-Message-Id') !== false) {
				$message_id = str_replace('X-Message-Id: ', '', $header);
			}
		}
	} catch (Exception $e) {
		error_log('que pasoMAILex'.print_r(json_encode($e->getMessage()), true));

	}
	//error_log('que pasoMAIL'.print_r(json_encode($response), true));
	return $message_id;

	// $sg = new \SendGrid(SENDGRID_API_KEY);
	// $from = new SendGrid\Email($usuario, $remitente);
	// $subject = $asunto;
	// $to = new SendGrid\Email('', $destinatario);

	// $content = new SendGrid\Content("text/html", $email_data['mensaje']);
	// $mail = new SendGrid\Mail($from, $subject, $to, $content);
	// if (!empty($email_data['ruta_file'])) {
	// 	$adjunto = file_get_contents(UPLOAD_PATH . $email_data['ruta_file'] . $email_data['name_file']);
	// 	if ($adjunto) {
	// 		$mail->addAttachment($adjunto, 'application/pdf', !empty($email_data['name_file_mail']) ? $email_data['name_file_mail'] : $email_data['name_file']);
	// 	} else {
			
	// 	}
	// }
	// if (count($email_data['multiple_email']) > 0) {
	// 	foreach ($email_data['multiple_email'] as $key => $value) {
	// 		$to_multiple = new SendGrid\Email('', trim($value));
	// 		$mail->personalization[0]->addTo($to_multiple);
	// 	}
	// }
	// if (count($email_data['multiple_cc']) > 0) {
	// 	foreach ($email_data['multiple_cc'] as $key => $value) {
	// 		$to_cc = new SendGrid\Email('', trim($value));
	// 		$mail->personalization[0]->addCc($to_cc);
	// 	}
	// }


	// $response = $sg->client->mail()->send()->post($mail);
	// //pre($response);
	// //echo $response->statusCode();
	// //print_r($response->headers());
	// //echo $response->body();
	// return $response;






}