brbunny/brmailer

BrMailer is a component for handling email using PHPMAILER

v1.1.4 2023-03-15 23:37 UTC

This package is auto-updated.

Last update: 2024-05-16 02:00:19 UTC


README

Maintainer PHP from Packagist Latest Version Software License Total Downloads

BrMailer is a component for handling emails using PHPMAILER.

Installation

BrMailer is available through Composer:

"brbunny/brmailer": "1.1.*"

or run

composer require brbunny/brmailer

Documentation

For more details on how to use BrMailer, see the example folder with details in the component directory

Configuration

To begin using BrMailer we need to configure the email data. Put constant BRMAILER in your project's configuration file and change the values according to your preference. To learn more visit Component PHPMailer

Para começar a usar o BrMailer precisamos configurar os dados do e-mail. Coloque constante BRMAILER no arquivo de configuração do seu projeto e mude os valores de acordo com sua preferência. Para saber mais visite Componente PHPMailer

<?php

define("BRMAILER", [
   "host" => "mail.host.com",
   "port" => "587",
   "user" => "user@example.com",
   "passwd" => "secret",
   "from" => [
      "name" => "From Name",
      "address" => "from@example.com"
   ],
   "reply" => [
      "name" => "Reply Name",
      "address" => "info@example.com"
   ],
   "options" => [
      "language" => "br", // Set Language Email
      "smtp_debug" => 0, // Enable verbose debug output
      "is_html" => true, // Set email format to HTML
      "auth" => true, // Enable SMTP authentication
      "secure" => "tls or ssl", // Enable TLS encryption
      "charset" => "utf-8" // Set email charset
   ]
]);
Bootstrap

To send email to just one recipient, add the destination email as a parameter in the bootstrap() function. However, you can add it with the addAddress() function or both together.

Para enviar e-mail para apenas um destinatário, adicione o e-mail de destino como parâmetro da função bootstrap(). No entanto, você pode adicioná-lo com a função addAddress() ou os ambos juntos.

<?php
require __DIR__ . '/vendor/autoload.php';

use BrBunny\BrMailer\BrMailer;

$email = new BrMailer();

// (string Subject, string Body, string RecipientAddress, string RecipientName)
$email->bootstrap(
    "Here is the subject",
    "This is the message body",
    "van@example.com", // E-mail is Optional
    "Van User" // Name is Optional
);
Template

Now you can assemble your html email template using BrPlates, create the template using the template() method. For more details access the sample folder and see how it works or visit BrPlates.

Agora você pode montar seu template de e-mail html usando BrPlates, basta criar o template usando o método template(). Para mais detalhes acesse a pasta de exemplo e veja como funciona ou visite BrPlates.

<?php

$template = $email->template("./theme")->renderTemplate("_theme", [
    "title" => "E-mail",
    "company" => "BrBunny"
]);

$email->bootstrap(
    "Here is the subject",
    $template
);
AddAddress

If you do not enter email as a parameter in the bootstrap function, you must use the addAddress() function.

Se você não inserir email como um parâmetro na função bootstrap, você deve usar a função addAddress().

<?php

$email->addAddress("joe@example.net", "Joe User");
$email->addAddress("jhow@example.com"); // Name is optional
AddCC

If you use the addAddress() or addCC() function to add more than one recipient, they will know who received the message.

Caso use função addAddress() ou addCC() para adicionar mais de um destinatário, os mesmos terão conhecimento de quem recebeu a mensagem.

<?php

$email->addCC("joe@example.net", "Joe User");
$email->addCC("jhow@example.com"); // Name is optional
AddBCC

The addBCC() function sends the email to more than one person, without one knowing that the other is receiving the same message.

A função addBCC() envia o e-mail para mais de uma pessoa, sem que uma saiba que a outra está recebendo a mesma mensagem.

<?php

$email->addBCC("joe@example.net", "Joe User");
$email->addBCC("jhow@example.com"); // Name is optional
Attachment
<?php

// Add Attachment in E-mail
$email->attach("/tmp/image.jpg", "Image");
$email->attach("/tmp/file.pdf"); // Name is optional
Send E-mail
<?php

// string $from, string $fromName, string $replyTo, string $replyToName
if($email->send()){
   // Message success
   echo "Success Send";
}else{
   // Get message error
   echo $email->fail()->getMessage();
}

Credits

License

The MIT License (MIT). Please see License File for more information.