Ir para conteúdo
Fórum Script Brasil
  • 0

PHP Warning:  file_get_contents(http://localhost:8080/assets/mail/template.html):  failed to open stream: HTTP request failed!


lucasdgimenez

Pergunta

Estou trabalhando em um projeto construído com php slim, onde eu tenho uma tela de cadastro que ao clicar em cadastrar aciona a rota /registrar da rota pai "/clientes"

image.thumb.png.7809acbfaa07743ccd499a2e05bc3293.png

 

O erro que gera é esse aqui:

image.png.a9bc23316417946939cec08cefa6c7bc.png

A linha do arquivo Email é essa:

image.png.00d403f95ccf880341ee447cb7967690.png

O codigo completo do arquivo Email.php é esse:
 

<?php

	
	namespace App\Services;

	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	error_reporting(E_ALL);

	use PHPMailer\PHPMailer\PHPMailer;
	
	class Email
	{
		
		private static $HOST = EMAIL_HOST;
		private static $LOGIN = EMAIL_LOGIN;
		private static $PASS = EMAIL_PASS;
		private static $PORT = EMAIL_PORT;
		private static $SMTPSecure = EMAIL_SMTP_SECURE;
		private static $SMTPAuth = EMAIL_SMTP_AUTH;
		private static $templateMail = BASEURL . 'assets/mail/template.html';
		
		public static function send(String $toEmail, String $toName, String $subject, String $message, String $replyTo = null, String $replyToName = null, $attachments = null, $copyTo = null)
		{
			if (ENV == 'local') {
				$toEmail = 'caleksitch@hotmail.com';
				//$toEmail = 'lucasdgimenez@gmail.com';
				$subject = "Teste Fundamenta - {$subject}";
			}

			/*$curl = curl_init();
			curl_setopt($curl, CURLOPT_URL, self::$templateMailURL);
			curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
			$templateMail = curl_exec($curl);

			if ($templateMail === false) {
				throw new \Exception("Failed to fetch template using cURL: " . curl_error($curl));
			}

			curl_close($curl);*/

			
			$templateMail = file_get_contents(self::$templateMail);

			$message = str_replace('HTMLMessage', $message, $templateMail);
			
			$mail = new PHPMailer;
			$mail->isSMTP();
			$mail->CharSet = 'UTF-8';
			$mail->SMTPDebug = 0; //2 para modo debug
			$mail->Host = self::$HOST;
			$mail->Port = self::$PORT;
			$mail->SMTPSecure = self::$SMTPSecure;
			$mail->SMTPAuth = self::$SMTPAuth;
			$mail->Username = self::$LOGIN;
			$mail->Password = self::$PASS;
			$mail->SMTPOptions = array(
				'ssl' => array(
					'verify_peer' => false,
					'verify_peer_name' => false,
					'allow_self_signed' => true
				)
			);
			$mail->setFrom(self::$LOGIN, 'Fundamenta');
			$mail->Subject = $subject;
			$mail->Body = $message;
			$mail->IsHTML(true);
			if ($replyTo !== null) {
				$mail->addReplyTo(trim($replyTo), $replyToName);
			}
			$mail->addAddress(trim($toEmail), $toName);
			if ($copyTo) {
				for ($i = 0; $i < sizeof($copyTo); $i++) {
					$mail->addCC($copyTo[$i]);
				}
			}
			if ($attachments) {
				foreach ($attachments as $attachment) {
					$mail->addAttachment($attachment[0], $attachment[1]);
				}
			}
			if (!$mail->send()) {
				throw new \Exception($mail->ErrorInfo);
			}
		}
		
		
	}

Já tentei buscar no google esse problema e a maioria indica a solução do curl em vez do file_get_contents, o problema é que ao tentar implementar essa solução do curl (que está comentada no código acima) o sistema roda um loading infinito, não sei exatamente qual pode ser o problema disso. 

A versão do php é 7.4 e a do apache é 2.4.52

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652,2k
×
×
  • Criar Novo...