PHP code example of effectra / mail

1. Go to this page and download the library: Download effectra/mail 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/ */

    

effectra / mail example snippets


use Effectra\Mail\Mailer;

// Create a mailer instance
$mailer = new Mailer(
    'smtp',         // Mail driver (e.g., 'smtp', 'sendmail')
    'mail.example.com',  // Mail server host
    587,            // Mail server port
    'username',     // Username for authentication
    'password',     // Password for authentication
    '[email protected]'  // "From" email address
);

$mail = new Mail();
// Set email recipients
$mail->to('[email protected]');
$mail->cc('[email protected]');
$mail->bcc('[email protected]');

// Set email subject and content
$mail->subject('Hello, world!');
$mail->text('This is the plain text content of the email.');
$mail->html('<p>This is the HTML content of the email.</p>');

// Send the email
try {
    $mailer->send($mail);
    echo 'Email sent successfully!';
} catch (Exception $e) {
    echo 'An error occurred while sending the email: ' . $e->getMessage();
}