nfephp-org/sped-mail

SPED 相关电子邮件生成和发送的 API。

v1.0.0 2021-10-15 14:50 UTC

This package is auto-updated.

Last update: 2024-09-18 18:45:47 UTC


README

电子邮件发送是 SPED 服务操作人员的基本需求之一。

根据法律规定,必须向各自的收件人发送包含 NFe 和 CTe XML 的电子邮件。

一些收件人错误地要求也发送有关辅助文档(DANFE、DACTE 或 DACCE)的 PDF 作为该电子邮件的附件。

其他要求将电子邮件发送到多个邮箱。

该 API 部分旨在提供这种便利,如果需要的话。

Join the chat at https://gitter.im/nfephp-org/sped-mail

Actions Status

Latest Stable Version Latest Version on Packagist License Total Downloads

Issues Forks Stars

如何安装

使用 composer,通过命令行添加此包

composer require nfephp-org/sped-mail

或将它添加到您的 composer.json 文件中

{
    "require": {
    	"nfephp-org/sped-mail": "^1.0"
    }
}

如何使用

该类可以用两种不同的方式使用。

1 - 使用静态方法

$resp = Mail::sendMail($config, $xml, $pdf, $addresses, $template, $pfx, $password, $mailer);

其中 : $config 是包含您 SMTP 配置的 stdClass 对象(必需)

$config = new stdClass();
$config->smtpdebug = 0; //0-no 1-client 2-server 3-connection 4-lowlevel
$config->host = 'smtp.example.com.br';
$config->port = 587; //25 ou 465 ou 587
$config->smtpauth = true;
$config->user = 'fulano@example.com.br';
$config->password = 'senha';
$config->secure = 'tls';
$config->authtype = ''; //'', CRAM-MD5, PLAIN, LOGIN, XOAUTH2
$config->from = 'fulano@example.com.br';
$config->fantasy = 'Fulanoda Silva';
$config->replyTo = 'ciclano@mail.com';
$config->replyName = 'Ciclano Moreira';
$config->smtpoptions = null; /*[
    'ssl' => [
        'verify_peer' => true,
        'verify_depth' => 3,
        'allow_self_signed' => true,
        'peer_name' => 'smtp.example.com',
        'cafile' => '/etc/ssl/ca_cert.pem',
    ]
];*/
$config->timeout = 130;

$xml 是您想发送的 XML 路径或内容(必需)

$xml = '../nfe.xml';

或者

$xml = file_get_contents('../nfe.xml');

同样的方法用于 $pdf(可选)

$pdf = '../nfe.pdf';

或者

$pdf = file_get_contents('../nfe.pdf');

$address 是包含您想要发送邮件的电子邮件地址的数组。这些电子邮件地址将被验证,无效的地址将被丢弃。如果没有传递地址列表,系统将查找 XML 中的地址并使用它们,如果存在的话。(可选)

$addresses = ['fulano@client.com.br'];

使用的模板可以用 $template 参数替换,这是可选的。请参考标准模板以创建自己的,请参阅 Base.php 类。

$template = '<p>Meu HTML {emitente} .... ';

pfx 是 pfx 证书的内容(可选),可以从文件或直接从数据库中读取。

$pfx = file_get_contents('path ao certificado pfx');

密码是用于使用 pfx 证书的密码(可选),当然,如果提供了证书,密码也必须提供。

$password = 'senha';

最后一个参数是 PHPMailer 的现有实例。

$mailer = new PHPMailer();

有关更多详细信息,请参阅 examples 文件夹中指定的示例。

注意:在失败的情况下将返回一个 EXCEPTION

如何发送给多个收件人

我们可以通过两种基本方式将电子邮件发送给多个收件人

1 - 在文档本身的 XML 中指定所有收件人

在这种情况下,我们可以使用 <obsCont> 标签,XML 中可能存在数十个此类字段,这肯定是最智能的指定多个收件人的方式,因为可以直接从 XML 中读取这些字段。

请注意,字段类型 xCampo="email" 现在是必需的,以便我们可以识别该字段指示电子邮件。

 <obsCont xCampo="email">
     <xTexto>fulano@yahoo.com.br</xTexto>
 </obsCont>

2 - 在此类中通过数组传递额外的地址

这种形式已在上面提到的变量 $addresses = [...] 中说明。

文档