Email sending with PHP

In order to send Emails with PHP it is neccesary to use the SMTP protocol and not the builtin mail() function from PHP. The mail() function is not available in our PHP Containers.

There are many ways of sending mails via SMTP under PHP. Good choices are PHPmailer, SwiftMailer and PEAR's Mail. PEAR's Mail is preinstalled in our PHP containers and can be used directly.

Example with PHPMailer

$mail = new PHPMailer();
$mail->SMTPAuth   = true;
$mail->SMTPSecure = "tls";
$mail->Host       = "";
$mail->Username   = "";
$mail->Password   = "super-secure-password";
$mail->From       = "";
$mail->FromName   = "Example Website";
$mail->To         = "";
$mail->Subject    = "Test Email";
$mail->Body       = "Test\n1\n2\n3";

Example with SwiftMailer

require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance()
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance()
    ->setSubject('Test Email')

Example with PEAR's Mail

require_once "Mail.php";
$smtp = Mail::factory('smtp', array(
    'host'     => "",
    'auth'     => true,
    'username' => "",
    'password' => "super-secure-password"));
$headers = array(
    'From'    => "",
    'To'      => "",
    'Subject' => "Example Email");
$body = "Test\n1\n2\n3";
$smtp->send($to, $headers, $body);