Skip to content

SMTP API - Quick Start

1. Create an account

If you don't have a Teenvio account, you'll need to create one for free

2. Check params

3. Launch email


# Install PHPMailer 
composer reqire phpmailer/phpmailer     



require './vendor/autoload.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that

//Create a new PHPMailer instance
$mail = new PHPMailer();

//Tell PHPMailer to use SMTP

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = '';

//Set the SMTP port number
$mail->Port = 58700;

//Set the encryption system to use: ssl
$mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full user for teenvio
$mail->Username = "user.plan";

//Password to use for SMTP authentication
$mail->Password = "pass";

//Set who the message is to be sent from
$mail->setFrom('', 'teenvio');

//Set who the message is to be sent to
$mail->addAddress('', 'Test contact');

//Set the subject line
$mail->Subject = 'PHPMailer Teenvio SMTP test';

//Custom options
$mail->addCustomHeader('X-Teenvio-ShowCab', 'yes');
$mail->addCustomHeader('X-Teenvio-SocialLinks', 'no');
$mail->addCustomHeader('X-Teenvio-Language', '3');
$mail->addCustomHeader('X-Teenvio-TrackingOpening', 'yes');
$mail->addCustomHeader('X-Teenvio-TrackingClicks', 'yes');

//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
<body bgcolor="#FFFFFF" text="#000000">
Esto es un email <b>html</b> para probar el servidor smtp-api de teenvio<br>
Un saludo,<br>
<u>V&iacute;ctor J. Chamorro</u> -<br>
', dirname(__FILE__));

//Replace the plain text body with one created manually
$mail->AltBody = '
Esto es un email *html* para probar el servidor smtp-api de teenvio
Un saludo,
_Victor J. Chamorro_ -

//send the message, check for errors
if (!$mail->send()) {
    echo "<br>Mailer Error: " . $mail->ErrorInfo;
    echo "<br><br>Details:<pre>";
    echo "</pre>";
} else {
    echo "<br>Message sent!";