PHP code example of piyo2 / mail

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

    

piyo2 / mail example snippets



$mail = new \piyo2\mail\Mail();

// Set sender
$mail->from('[email protected]', 'John Doe');

// Set subject
$mail->subject('Hello World');

// Set body
$mail->message('Hello World');

// Set HTML body
$mail->htmlMessage('<h1>Hello World</h1>');

// Add header
$mail->header('X-My-Header', 'My Header');

// Add attachment
$attachment = \piyo2\mail\Attachment::fromFile('/path/to/file', 'text/plain', 'file.txt');
$mail->attach($attachment);

$other = \piyo2\mail\Attachment::fromContent('Hello World', 'text/plain', 'hello.txt');
$mail->attach($other);

// Send mail
$mail->send('[email protected]');