PHP code example of genkgo / mail

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

    

genkgo / mail example snippets



use Genkgo\Mail;

$message = (new Mail\MessageBodyCollection('<html><body><p>Hello World</p></body></html>'))
    ->withAttachment(new Mail\Mime\FileAttachment('/order1.pdf', new Mail\Header\ContentType('application/pdf')))
    ->createMessage()
    ->withHeader(new Mail\Header\Subject('Hello World'))
    ->withHeader(Mail\Header\From::fromEmailAddress('[email protected]'))
    ->withHeader(Mail\Header\To::fromSingleRecipient('[email protected]', 'name'))
    ->withHeader(Mail\Header\Cc::fromSingleRecipient('[email protected]', 'name'));

$transport = new Mail\Transport\SmtpTransport(
    Mail\Protocol\Smtp\ClientFactory::fromString('smtp://user:pass@host/')->newClient(),
    Mail\Transport\EnvelopeFactory::useExtractedHeader()
);

$transport->send($message);