Sending with PHPMailer
Integrate Mailofly into standard PHP projects using PHPMailer.Installation
composer require phpmailer/phpmailer
Example
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
// Server settings
$mail->isSMTP();
$mail->Host = 'smtp.mailofly.com';
$mail->SMTPAuth = true;
$mail->Username = 'mailofly';
$mail->Password = 'mfly_live_your_api_key';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
// Recipients
$mail->setFrom('support@yourcompany.com', 'Acme Support');
$mail->addAddress('customer@example.com');
// Content
$mail->isHTML(true);
$mail->Subject = 'Your Order Confirmation';
$mail->Body = '<h1>Thank you for your order!</h1>';
$mail->AltBody = 'Thank you for your order!';
$mail->send();
echo 'Message has been sent successfully';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}