04 October 2017

PHP Mailer Class

- PHPMailer is a Free Email Transfer Class for PHP, supporting SMTP and POP3, HTML messages, attachments, and more. Sends email via sendmail, PHP mail(), QMail, or directly
with SMTP.

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAllBMVEVmm0H////+/v5jmT3p8OVonkNeljX6/Pmfv4xfljh4p1Zmm0DU4stimjljmj38/fzy9u9loTlinDdqo0G30Kauy5tZky6kxI5fnS+Ktmzg6dlzqU2dwIVwoU18r1nE2beAsGCNtHNTjyWFrmnn8OGNsnS70a2XvH/G17vb6NOKtW+qyJWErWrE2LWrxZp8qV6WuIBPjhu29StSAAANTElEQVR4nOWda3eqOBSGYUAQQyKCIiJ4Qeultur5/39ugmi9EdyBINC+n2adtQbzNDv7RkgkuVzplqX65rS/Cz4XnVBKFHYWn8GuPzV91bL0kkcglfdoa2lu9sFo0sI2FSaEoDOhRP87+cfWZBTsN+bSKm8YZRFu++3FZOxgCoZ+wJ6EEEXFzniyaPe3JY1EPKFu+YMR9nqYKGy0B1CF4J6HRwO/BJsVTKj7m+EM204LyHarlmPj2XDjC4YUSqiu5hMHE+jUpUwmwc5kvlJFDkoYoa5+z+weUXLTXaSQnj37VoXNpCBCywzGtlOY7iLHHgemIP8qhNAajMY4v22mCeHxaCCEsTihvl1T6xTLd2Kk1rreFjfWooT6JnBs8XhnSOwEZlHGgoTmp2jzfGQcf5rVEermrAzzfGAkvVmheSxAaAY2KRkvEbGDAvOYm9AKxvgtfLHwOMjtV3MSqgPbfhvfibE3yJnp5CKkC7A0/8kSsnMuxzyE1EDfswDvRfKZKj+hPvVKDRBsIdyb8k8jN6EfONXwnRidwC+b0JxUNIFnRDzhDRx8hGrQK14eFZPSC/icKhehP3tviEiXPeKyVB7CzeR9MT5LeLIphVAPvKot9CLFC+A+FUyoBnWw0Its+GKEEi5H4noUIuSMlmIJTa8eS/Aq4gHDBozwu5I0LVtkPBVH2K8hYIzYF0TYHXhVwzDkDboiC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q5LYDtjlUl5CWQ+8uvRuFI9d8BYglOXNpB4dODzhuQ+Vh1D2Z3WwVHvE6KoJIKSLsVe1pSo9+BLMQUjDxiTn9VdihPAEGCRyE8p+UGEmjpyAy0JzEcr61KtoGpHdm8J9aH7C+MzHSpI4Mg6e3/CWQyjr5uzt74mRPTP5JzAvIXWqA/u9sRH3BnwutCjhyVTfxohwPgMtRkgDR2C/ZzliO+ANEWII4+XYI2WvR0R6ORegAEIq83Ncauig9vlZYP4EENJ5DJzS/CrCTlBo/kQQxveUre0yjJWap73eFuUTQSjHF42MRBsrNc/RILf/vJUQQspoBmNbXJ/DsceBKYRPGCE1VvV7Rq21eHGlUOucfavFzfMsYYSx1NV84uACaxIR7Ezmq5zZS7qEEtKZ9DfDGbadPLfTthwbz4YbX9jsJRJMSKVb/mCEvR4mzGsenqZOIbjn4dHAtwTjyWUQJtr224vJ2MGYEMQGRYgQjJ3xZNHub18/NJfKIqSyluZmH4wmLWxTUdSfLJZykeQfW5NRsN+YS0F+M00lEp6kx/fKmNP+LvhcdMLzggs7h89g15+a8b0z4u3yXv8DBP086EpTBnMAAAAASUVORK5CYII=



- Download PHPMailer 5.2.1.

Example, uses PHPMailer to send email via SMTP, using a GMail account.

  1. <?php
    include('PHPMailer_5.2.1/class.phpmailer.php');
    
    // Here sets data for email
    $from = 'name@yourdomain.com';
    $from_name = 'Your name';
    $to = 'whoto@domain.com';
    $toname = 'Receiver Name';
    $subject = 'Subject for email';
    $msg = 'The email message, can contains HTML tags';
    
    $mail             = new PHPMailer();
    $mail->IsSMTP();                                // telling the class to use SMTP
    $mail->Host       = "smtp.gmail.com";           // SMTP server
    $mail->SMTPAuth   = true;                       // enable SMTP authentication
    $mail->SMTPSecure = "ssl";                      // sets the prefix to the servier
    $mail->Host       = "smtp.gmail.com";           // sets GMAIL as the SMTP server
    $mail->Port       = 465;                        // set the SMTP port for the GMAIL server
    $mail->Username   = 'name@gmail.com';           // your GMAIL account
    $mail->Password   = 'password';                 // GMAIL password
    
    $mail->SetFrom($from, $from_name);
    $mail->AddReplyTo($from, $from_name);
    $mail->Subject = $subject;
    $mail->MsgHTML($msg);                 // to send with HTML tags
    
    $mail->AddAddress($to, $toname);
    
    
    if(!$mail->Send()) {
      echo 'Mailer Error: '. $mail->ErrorInfo;
    } else {
      echo 'Message sent!';
    }
    ?>
 Example, uses PHPMailer to send email via PHP mail(), with HTML tags and attachments.

  1. <?php
    include('PHPMailer_5.2.1/class.phpmailer.php');
    
    // Here sets data for email
    $from = 'name@yourdomain.com';
    $from_name = 'Your name';
    $to = 'whoto@domain.com';
    $toname = 'Receiver Name';
    $subject = 'Subject for email';
    $msg = 'The email message, can contains HTML tags';
    
    $mail = new PHPMailer();
    $mail->SetFrom($from, $from_name);
    $mail->AddReplyTo($from, $from_name);
    $mail->AddAddress($to, $toname);
    $mail->Subject = $subject;
    $mail->MsgHTML($msg);                 // to send with HTML tags
    
    // add attachments
    $mail->AddAttachment('attachment_file.zip');      // attachment 1
    $mail->AddAttachment('attachment_file.jpg');      // attachment 2
    
    if(!$mail->Send()) {
      echo 'Mailer Error: '. $mail->ErrorInfo;
    } else {
      echo 'Message sent!';
    }
    ?>


Start typing and press Enter to search