gabriel-binotti / email
Simple example to send email with phpmailer
Requires
- php: >=7.0
- phpmailer/phpmailer: ^6.9
This package is auto-updated.
Last update: 2025-04-04 23:13:09 UTC
README
Require
- PHP >= 7.0
- Composer installed
- A server mail
Install
You can install this class using the line-command
composer require gabriel-binotti/email
Step 0
You need config the file email.ini in vendor/appEmail/config/email.ini
host = nameserve username = user password = password auth = 'true' or 'false' port = 587 or 465 charset = 'UTF-8' secure = 'false' or 'true'
After you can to use that class by examples above.
index.php
use GabrielBinottiEmail\Email; require_once "vendor/autoload.php"; try { Email::email('email') // name file .ini ->debug() // active show debug (server, client or off "default is off") ->from("email", "name") // sender's email , name (Can your name or you company...) ->reply("email", "name ") // answer email (optional) ->destination("email", 'name') // recipient email , name ->subject("subject email") // subject email ->bodyHtml('text body') // text body ->options([ "ssl" => [ 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ] ]) ->send(); // send email } catch (Exception $e) { echo $e->getMessage(); }
options() is configured based in your server if they have SSL or not.
You can to use template HTML in body email, change bodyHtml() to template()
template('template.html');
The template you create in vendor/appEmail/template/, by default the second parameter ir an array empty, but you can send an array to replace.
$arrayReplace = [ [ "before" => "value", "after" => "value", ], [ "before" => "value", "after" => "value", ] ]; template('template.html', $arrayReplace);
You can send file in you email. You need add file in vendor/appEmail/files/
addFile("filename.format", "name file");
You can add image in your body. Add the image in vendor/appEmail/images/
addImage("image.format", "name image");
To add image in your body email, you need create a template, example above:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <img src="cid:nameImage" alt=""> </body> </html>