Sample code for 30+ languages & platforms
PHP Requires Chilkat v11.0.0+

Create, save, and reopen a plain-text email

See more Email Object Examples

Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\Email;

// Assumes Chilkat is unlocked. See Global Unlock Sample.

$email = new Email();
$email->From = 'Sam Lee <sam@example.com>';
try {
    $email->AddTo('Alex Rivera', 'alex@example.net');

    $email->Subject = 'Hello';
    $email->Body = 'This is a plain-text message.';
    $email->SaveEml('message.eml');

    $received = new Email();
    $received->LoadEml('message.eml');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

echo $received->From, "\n";
echo $received->Subject, "\n";
echo $received->GetPlainTextBody(), "\n";