public enviaMail ( string $pathXml = '', array $aMails = [], string $templateFile = '', boolean $comPdf = false, string $pathPdf = '' ) : boolean | ||
$pathXml | string | |
$aMails | array | |
$templateFile | string | path completo ao arquivo template html do corpo do email |
$comPdf | boolean | se true o sistema irá renderizar o DANFE e anexa-lo a mensagem |
$pathPdf | string | |
Résultat | boolean |
public function enviaMail($pathXml = '', $aMails = array(), $templateFile = '', $comPdf = false, $pathPdf = '')
{
$mail = new MailNFe($this->aMailConf);
// Se não for informado o caminho do PDF, monta um através do XML
if ($comPdf && $this->modelo == '55' && $pathPdf == '') {
$docxml = Files\FilesFolders::readFile($pathXml);
$danfe = new Extras\Danfe($docxml, 'P', 'A4', $this->aDocFormat['pathLogoFile'], 'I', '');
$id = $danfe->montaDANFE();
$pathPdf = $this->aConfig['pathNFeFiles'] . DIRECTORY_SEPARATOR . $this->ambiente . DIRECTORY_SEPARATOR . 'pdf' . DIRECTORY_SEPARATOR . $id . '-danfe.pdf';
$pdf = $danfe->printDANFE($pathPdf, 'F');
}
if ($templateFile != '') {
$mail->setTemplate($templateFile);
}
if ($mail->envia($pathXml, $aMails, $comPdf, $pathPdf) === false) {
throw new Exception\RuntimeException('Email não enviado. ' . $mail->error);
}
return true;
}
<?php error_reporting(E_ALL); ini_set('display_errors', 'On'); include_once '../../bootstrap.php'; //NOTA: o envio de email com o DANFE somente funciona para modelo 55 // o modelo 65 nunca requer o envio do DANFCE por email use NFePHP\NFe\ToolsNFe; $xml = __DIR__ . '/../xml/35150300822602000124550010009923461099234656-nfe.xml'; $nfe = new ToolsNFe('../../config/config.json'); $nfe->setModelo('55'); $aMails = ['*****@*****.**']; //se for um array vazio a classe Mail irá pegar os emails do xml $templateFile = ''; //se vaizio usará o template padrão da mensagem $comPdf = true; try { $nfe->enviaMail($xml, $aMails, $templateFile, $comPdf); } catch (NFePHP\Common\Exception\RuntimeException $e) { echo $e->getMessage(); }