GreenArrow Email Software Documentation

PHPMailer SimpleMH Example

Below is an example of using the SimpleMH Injection Method with PHPMailer. See the SimpleMH Headers page for information on what the headers shown in this document represent.

<?php

// phpmailer-simplemh-example.php
// Inject a single test message into GreenArrow Engine using PHPMailer and SimpleMH

// Use PHPMailer
require_once('/usr/share/php/PHPMailer/class.phpmailer.php');
require_once('/usr/share/php/PHPMailer/class.smtp.php');

$mail = new PHPMailer();
$mail->IsSMTP(); // tell the class to use SMTP
//$mail->SMTPDebug = 2; // uncomment to print debugging info

// Timezone
date_default_timezone_set('America/Chicago');

// GreenArrow Engine installation settings
$mail->Host = "mta.example.com"; // Connect to this GreenArrow server
$mail->SMTPAuth = true; // enables SMTP authentication. Set to false for IP-based authentication
$mail->Port = 587; // SMTP submission port to inject mail into. Usually port 587 or 25
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "password"; // SMTP password

// Campaign Settings
$mail_class = "transactional"; // Mail Class to use
$mail->SetFrom("[email protected]", "From Name");
$mail->Subject = "SimpleMH PHPMailer Example";
$mail->MsgHTML("HTML body");
$mail->AltBody = "Text body";

// Individual Recipient Settings
$recipient = "[email protected]";
$recipient_name = "Recipient Name";

// Generate the To: and X-GreenArrow-MailClass headers
$mail->AddAddress($recipient, $recipient_name);
$mail->addCustomHeader("X-GreenArrow-MailClass: $mail_class");

// Send the campaign 
if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo . "\n";
} else {
    echo "Message sent!\n";
}