PHP code example of gartmedia / php-email-library

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

    

gartmedia / php-email-library example snippets



use Email\Email;
use Email\EmailAddress as Address;

$data = [
    "from" => Address::newAddress($email, $name),
    "to" => [
        Address::newAddress("[email protected]", "Max Mustermann")
    ],
    // add custom fields to message body
    "body" => [
        "subject" => $subject,
        "customField" => $customField
    ],
    // attach files to mail
    "files" => [
      ["tmp_name" => "temp", "name" => "test.txt"],
      ["tmp_name" => "temp2", "name" => "test2.txt"]
    ]
];

$settings = [
    // enables recaptcha authentication
    "recaptcha" => [
        "secret" => "your recaptcha secret",
        "response" => $recaptchaResponse,
        "scoreThreshold" => 0.9 // recaptcha v3 score threshold (default = 0.5)
    ],
    "html" => true // enable html mail
];

$mail = new Email($data, $settings);

try {
    $mail->send();
} catch (Exception $e) {
    echo $e;
}