How do I set up outbound SMTP using PHPMailer?



    How do I set up outbound SMTP using PHPMailer?
    How do I use outMail in PHP?


    The following example of code assumes you have already got a fully functional webserver and the PHPMailer Classes Installed

    Example code outmail-phpmailer.php

        require_once("class.phpmailer.php" );
        $mail = new PHPMailer(true);    // the true param throws exceptions that we need to catch
        $mail->IsSMTP();             // telling the class to use SMTP
        try {
            // Enables SMTP debug information (for testing)
            //    1 = errors and messages
            //    2 = messages only
            $mail->SMTPDebug = 1;                    
            // Enable SMTP authentication
            $mail->SMTPAuth = true;
            // SMTP server
            $mail->Host = "";   
            // set the SMTP port for the outMail server        
            //    use either 25, 587, 2525 or 8025
            $mail->Port = 25;
            // outMail username        
            $mail->Username = "username";
            // outMail password
            $mail->Password = "password";
            // Message details
            $mail->AddReplyTo('', 'First Last');
            $mail->AddAddress('sender@there-domain.local', 'First Last');
            $mail->SetFrom('', 'First Last');
            $mail->Subject = 'PHPMailer Test using outMail';
            $mail->AltBody = 'Text Message goes here.';
            $mail->MsgHTML('HTML Message goes here.');
            // Send the Message
            echo "Message Sent OK</p>\n";
        catch (phpmailerException $e){echo $e->errorMessage();} //Pretty error msg from PHPMailer
        catch (Exception $e){echo $e->getMessage();} //Boring error messages from anything else!


    Summary of server details

    Outgoing server

    As provided in your signup email.

    Outgoing server protocol


    Outgoing server port

    25, 587, 465

    Authentication Type

    Basic Authentication


    As provided


    As provided

    Was this article helpful?
    0 out of 0 found this helpful


    Powered by Zendesk