Beispiel #1
0
 /**
  * Creates a new message by parsing a string containing a complete mail
  * message. The headers are parsed and stored; the body is left intact.
  *
  * \param $data
  *   A string with a complete mail message
  *
  * \return
  *   A new AnewtMailMessage instance
  */
 public static function from_string($data)
 {
     /* Sanity check */
     assert('is_string($data)');
     /* New message */
     $message = new AnewtMailMessage();
     /* Split headers from body */
     list($headers, $body) = preg_split('/\\n{2,}/', $data, 2);
     /* Parse headers and body */
     $message->parse_headers($headers);
     $message->parse_body($body);
     /* Parsed messages should not be sent out again (well, not without
      * explicit telling that they should be) */
     $message->set('can-send', false);
     /* Return the message */
     return $message;
 }
Beispiel #2
0
#!/usr/bin/php -q
<?php 
require_once '../anewt.lib.php';
anewt_include('mail');
$m = new AnewtMailMessage();
function usage()
{
    printf("Usage: %s address\n", $_SERVER['argv'][0]);
    exit(1);
}
$address = array_get_default($_SERVER['argv'], 1, null);
if (is_null($address)) {
    echo 'Error: no address specified', NL;
    usage();
}
$m->add_header('To', $address);
$m->add_header('Subject', 'Test');
$m->add_header('From', $address);
$m->set('body', 'This is a test message sent using the AnewtMailMessage class.');
$result = $m->send();
if ($result) {
    echo 'Mail sent successfully.', NL;
} else {
    echo 'Sending mail failed.', NL;
}