Mails : server

Setting up mail server

The setup() method is used to load the default setup either as an array or a file.

Setting up the mail server through file can be done by returning the PHPMailer server configuration from a mail setup file. The configurations are set as array and then file is loaded using the setup() method. The method accepts the filename or file path by using the dot convention. for example, a file path of mail/server.php will be supplied as mail.server . This makes it easier to load the server config file.

1. File Setup Method
Sample Server File Configuration (server.php)

  <?php

    return [
        'SMTPAuth'   => true,  // Enable SMTP authentication
        'Host'       => 'smtp.mail.com', // Specify main and backup SMTP servers smtp.gmail.com / website hostname
        'Username'   => 'info@site.com', // SMTP username e.g info@site.com..
        'Password'   => '123abc',  // SMTP password  ..
        'SMTPSecure' => 'tls', // Enable TLS encryption, PHPMailer::ENCRYPTION_STARTTLS`PHPMailer::ENCRYPTION_SMTPS`
        'Port'       => 587,   // TCP port to connect to (mostly constant)
    ];

    
Sample: Loading Server File

  <?php

    $mailer = new Mailer;

    $mailer->server('server'); // e.g server.php

    

2. Array Setup Method
The array setup method is done by supplying the configuration arrays themselves directly into the server() method.
Sample: Server Array Configuration / Modification

  <?php

    $mailer = new Mailer;
    
    // loading array directly
    $mailer->server([
        'SMTPAuth'   => true,  // Enable SMTP authentication
        'Host'       => 'smtp.mail.com', // Specify main and backup SMTP servers smtp.gmail.com / website hostname
        'Username'   => 'info@site.com', // SMTP username e.g info@site.com..
        'Password'   => '123abc',  // SMTP password  ..
        'SMTPSecure' => 'tls', // Enable TLS encryption, PHPMailer::ENCRYPTION_STARTTLS`PHPMailer::ENCRYPTION_SMTPS`
        'Port'       => 587,   // TCP port to connect to (mostly constant)
    ]); 

    

It is however import to note that the array method overides any default configuration set.