PHP code example of brbunny / brmailer

1. Go to this page and download the library: Download brbunny/brmailer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brbunny / brmailer example snippets




define("BRMAILER", [
   "host" => "mail.host.com",
   "port" => "587",
   "user" => "[email protected]",
   "passwd" => "secret",
   "from" => [
      "name" => "From Name",
      "address" => "[email protected]"
   ],
   "reply" => [
      "name" => "Reply Name",
      "address" => "[email protected]"
   ],
   "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
   ]
]);


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",
    "[email protected]", // E-mail is Optional
    "Van User" // Name is Optional
);



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

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



$email->addAddress("[email protected]", "Joe User");
$email->addAddress("[email protected]"); // Name is optional



$email->addCC("[email protected]", "Joe User");
$email->addCC("[email protected]"); // Name is optional



$email->addBCC("[email protected]", "Joe User");
$email->addBCC("[email protected]"); // Name is optional



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



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