SMTP mailer with authentication

Sections

    It is important to note that our servers do not allow you to send emails from your website without authentication.

    If you are sending emails trough php scripts it is easy to add smtp functionality, for most if not all content management systems have plug-ins or built in options to enable smtp authentication.

    We have included a zip-file with the needed classes and functions to be able to send emails via smtp if you are using custom php code.
    You can find the files in this PHPMailer-master download here

    How to use:

    You will need to have at least these two files where you are using your script or include them in your relative path, they are as follows :

    Class.phpmailer.php
    Class.smtp.php

    Using the code is quite easy , the most important step Is including the file in your script :

    require ‘class.phpmailer.php’;

    Next you need to pass the email parameters:

    $mail = new PHPMailer;

    $mail->IsSMTP(); // Set mailer to use SMTP
    $mail->Host = ‘refer to webmail for smtp settings‘; // Specify main and backup server
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = ‘no_reply@yourdomain_name.co.za’; // SMTP username
    $mail->Password = ‘••••••••••’; // SMTP password
    $mail->SMTPSecure = ‘none’; // Enable encryption, ‘ssl’ also accepted

    $mail->From = ‘Your_email_address@yourdomain_name.co.za’;
    $mail->FromName = ‘Your name’;
    $mail->AddAddress(‘your_recipeint@email.com’); // Add a recipient,this can be added as a array eg array(’emailone@email.ccom’,’emailtwo@email.com’,”)
    $mail->AddReplyTo(‘your_replyto_address@email.com’);

    $mail->WordWrap = 50; // Set word wrap to 50 characters
    $mail->IsHTML(true); // Set email format to HTML

    $mail->Subject = ‘php email’;
    $mail->Body = ‘

    Here you can add any html and php to send in the body of the email.

    ‘;
    $mail->AltBody = ‘

    ‘;

    if(!$mail->Send()) {
    alert(“Error: Message could not be sent!”); // this can be commented out if you don’t need to see the result
    echo ‘Mailer Error: ‘ . $mail->ErrorInfo; // this can be commented out if you don’t need to see the result
    exit;
    }

    alert(“Success: Message has been sent!”); // this can be commented out if you don’t need to see the result

    And that is all that is needed to send email with authentication through php, if your smtp username and password is correct your emails should go trough.

    Related Articles

    in MSPControl Host Panel (Legacy) Tags: php mailerphp smtpSMTP Mailer
    Did this article answer your question?