PHPMailer Single Recipient Example
×
For API key Please contact with us at our SMTPprovider web chat
For API key Please contact with us at our SMTPprovider web chat
Example
Below is an example of Email sending through PHPMailer
<?php
// Inject a single test message using PHPMailer
// Use PHPMailer
require_once('PHPMailer/class.phpmailer.php');
require_once('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');
// SMTPProvider Engine installation settings
$mail->Host = "mta.example.com"; // Connect to this SMTPProvider server
$mail->SMTPAuth = true; // enables SMTP authentication.
$mail->Port = 587; // SMTP submission port to inject mail into. Usually port 587
$mail->Username = "smtpprov-u00100123"; // SMTP username
$mail->Password = "PASSWORD"; // SMTP password
// Campaign Settings
$mail_class = "transactional"; // Mail Class to use
$mail->SetFrom("test@example.com", "From Name");
$mail->Subject = "PHPMailer Example";
$mail->MsgHTML("HTML body");
$mail->AltBody = "Text body";
$mail->addAttachment('images/phpmailer_mini.png');
// Individual Recipient Settings
$recipient = "recipient@example.com";
$recipient_name = "Recipient Name";
// Generate the To: and X-SMTPProvider-MailClass headers
$mail->AddAddress($recipient, $recipient_name);
$mail->addCustomHeader("X-SMTPProvider-MailClass: $mail_class");
// Send the campaign
if(!$mail->Send()) {
echo "Mailer Error: ". $mail->ErrorInfo;
} else {
echo "Message sent";
}