use phpmailer to send emails code example

Example 1: phpmailer example php

<?php

require_once('class.phpmailer.php');

$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->SMTPDebug = 1;
$mailer->Port = 587; //Indica a porta de conexão 
$mailer->Host = 'smtplw.com.br';//Endereço do Host do SMTP 
$mailer->SMTPAuth = true; //define se haverá ou não autenticação 
$mailer->Username = 'smtplocaweb'; //Login de autenticação do SMTP
$mailer->Password = 'Gwb9etA323'; //Senha de autenticação do SMTP
$mailer->FromName = 'Bart S. Locaweb'; //Nome que será exibido
$mailer->From = '[email protected]'; //Obrigatório ser 
a mesma caixa postal configurada no remetente do SMTP
$mailer->AddAddress('[email protected]','Nome do 
destinatário');
//Destinatários
$mailer->Subject = 'Teste enviado através do PHP Mailer 
SMTPLW';
$mailer->Body = 'Este é um teste realizado com o PHP Mailer 
SMTPLW';
if(!$mailer->Send())
{
echo "Message was not sent";
echo "Mailer Error: " . $mailer->ErrorInfo; exit; }
print "E-mail enviado!"
?>

Example 2: how to setup php mailer

<?php
    include "emails/PHPMailer/PHPMailerAutoload.php"; 
	//or just include the php mailer class 
    //Create a new PHPMailer instance
    $mail = new PHPMailer(); 

    $mail->IsSMTP(); 
    $mail->SMTPDebug = 1; 
    $mail->SMTPAuth = true; 
    $mail->SMTPSecure = 'ssl'; 
    $mail->Host = "smtp.gmail.com";
	/*
    
    you also need to set the `allow less secure app` = ON 
    in your gmail account which you want to use here 
    :) 
    on then you will be able to send the emails from your account
    using phpMailer
    
    */
    $mail->Port = 465; 
    $mail->IsHTML(true);
    //Username to use for SMTP authentication
    $mail->Username = "@gmail.com";
    $mail->Password = "";
    //Set who the message is to be sent from
    $mail->setFrom('[email protected]', 'Zubair Mushtaq');
    //Set an alternative reply-to address
    $mail->addReplyTo('[email protected]', 'Secure Developer');
    //Set who the message is to be sent to
    $mail->addAddress('[email protected]', 'Abulogicss');
    //Set the subject line
    $mail->Subject = 'PHPMailer SMTP test';
    //Read an HTML message body from an external file, convert referenced images to embedded,
    //convert HTML into a basic plain-text alternative body
    $mail->msgHTML("convert HTML into a basic plain-text alternative body");
    //Replace the plain text body with one created manually
    $mail->AltBody = 'This is a plain-text message body';

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

Tags:

Php Example