PHP code example of spencer14420 / sp-php-email-handler

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

    

spencer14420 / sp-php-email-handler example snippets


    

use spencer14420\PhpEmailHandler\EmailHandler;

$emailHandler = new EmailHandler('/path/to/config.php');

$emailHandler->handleRequest();



use spencer14420\PhpEmailHandler\EmailHandler;

try {
    $emailHandler = new EmailHandler('/path/to/config.php');
    $emailHandler->handleRequest();
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}

#### REQUIRED ####

$mailboxEmail = '[email protected]';
// The email address where messages from the contact form will be sent.
// This must be provided and must be a valid email address.


#### OPTIONAL ####

$fromEmail = '[email protected]';
// The email address used as the "From" address in outgoing emails.
// If not provided, it defaults to the `$mailboxEmail`.

$replyToEmail = '[email protected]';
// The email address used as the "Reply-To" address in outgoing emails.
// If not provided, it defaults to the `$mailboxEmail`.

$siteDomain = 'example.com';
// The domain name of the website (e.g., example.com).
// If not provided, it defaults to the server's host name (`$_SERVER['HTTP_HOST']`).

$siteName = 'Example';
// The name of the website, used in email subjects and greetings.
// If not provided, it is derived from `$siteDomain` (e.g., "Example" for "example.com").

$captchaToken = '';
// If using a CAPTCHA, this should be set to the POST variable containing the CAPTCHA token.
// If CAPTCHA is not used, leave this empty.

$captchaSecret = '';
// The secret key for verifying CAPTCHA responses,