Investeerders

Kennisbank

1.000 veelgestelde vragen, 500 tutorials en uitlegvideo's. Hier vind je alleen maar oplossingen!

Using PHPMailer on Infomaniak

Bijwerken 12-11-2026

This guide explains how to use PHPMailer with Infomaniak Web Hosting to send emails from a website.

 

⚠ WARNING ⚠

Infomaniak guarantees that its services comply with standard protocols (IMAP, S3, etc.), but does not provide additional support for external services or software, as their configuration may change depending on the provider or publisher. (❓: help). This guide is therefore provided for informational purposes only, and its implementation remains your responsibility (❓: help). If needed, a qualified person can assist you (❓: help). 


 

Introduction

  • PHPMailer is a PHP library that allows you to create and send emails from a website, particularly via SMTP.
  • It allows you to send messages in HTML format, add an alternative text version, manage attachments, and use SMTP authentication.
  • For authenticated sending via SMTP, the PHP environment used by the website must be compatible with a recent encrypted connection, specifically TLS 1.2 or higher.
    • An outdated version of PHP or the OpenSSL library used by PHP may cause a connection or authentication error, even if the email address and password are correct.
    • Do not use PHP 5.3/5.4 for this type of sending; use a recent and supported version of PHP.
  • With authenticated SMTP sending, the address used as the sender must match the email address used for SMTP authentication.

 

Install PHPMailer

To use PHPMailer, install the library in your website's files.

  1. Download PHPMailer from its official repository (❓: help) or install it with Composer if your project uses it.
  2. Copy the PHPMailer files into a directory on your website using FTP (❓: help).
  3. Upload the necessary files to your PHP script, adapting the path according to the location you choose:

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    require __DIR__ . '/PHPMailer/src/Exception.php';
    require __DIR__ . '/PHPMailer/src/PHPMailer.php';
    require __DIR__ . '/PHPMailer/src/SMTP.php';

 

Configure SMTP sending with Infomaniak

Use the following authenticated SMTP settings:

  • SMTP server: mail.infomaniak.com
  • Port: 465
  • Encryption: SMTPS / SSL-TLS
  • Authentication: required
  • Username: the complete email address
  • Password: the password for the email address used

Example of a complete configuration:

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require __DIR__ . '/PHPMailer/src/Exception.php';
require __DIR__ . '/PHPMailer/src/PHPMailer.php';
require __DIR__ . '/PHPMailer/src/SMTP.php';

$mail = new PHPMailer(true);

try {
    // SMTP configuration
    $mail->isSMTP();
    $mail->Host       = 'mail.infomaniak.com';
    $mail->SMTPAuth   = true;
    $mail->Username   = 'sender@domain.xyz';
    $mail->Password   = 'your_email_password';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
    $mail->Port       = 465;
    $mail->CharSet    = 'UTF-8';

    // Sender information
    $mail->setFrom('sender@domain.xyz', 'Site Name');
    
    // Recipient
    $mail->addAddress('recipient@example.com');
    
    // Optional reply-to address
    $mail->addReplyTo('sender@domain.xyz', 'Site Name');
    
    // Message content
    $mail->isHTML(true);
    $mail->Subject = 'Message sent from the website';
    $mail->Body    = '<p>HTML body content.</p>';
    $mail->AltBody = 'Plain text body content.';
    
    $mail->send();
    echo 'Message sent successfully';
} catch (Exception $e) {
    echo 'Message could not be sent. Error: ' . htmlspecialchars($mail->ErrorInfo);
}

If your application requires the use of port 587, use STARTTLS:

$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port       = 587;

 

Check the PHP version and TLS compatibility

Authenticated SMTP sending requires a recent encrypted connection. If the site uses a version of PHP that is too old, for example PHP 5.3, or an outdated OpenSSL library, PHPMailer may fail before or during authentication. The errors may then be misleading, for example:

  • SMTP connect() failed
  • Could not authenticate
  • stream_socket_enable_crypto()
  • an authentication error even though the password is correct

In this case, check the following:

  1. the PHP version used by the website;
  2. the OpenSSL version used by PHP;
  3. the version of PHPMailer used by your project;
  4. the correspondence between the SMTP port and the chosen encryption method.

For reliable configuration, use a recent version of PHP that is compatible with TLS 1.2 or higher, as well as a current version of PHPMailer. If necessary, refer to these guides:

 

Resolving a Sender Mismatch Error

The error Sender mismatch SMTP code: 550 Additional SMTP info: 5.7.1 can occur when the address used as the sender does not match the email address used for SMTP authentication. Here is an example to avoid:

$mail->Username = 'sender@domain.xyz';
$mail->setFrom('another-address@domain.xyz', 'Site Name');

In this example, the script authenticates with sender@domain.xyz, but attempts to send the message using a different sender address.

Use the same email address for SMTP authentication and for the sender:

$mail->Username = 'sender@domain.xyz';
$mail->setFrom('sender@domain.xyz', 'Site Name');

The sender name can be customized, but the email address must remain consistent with the SMTP account used.

In the case of a contact form

If a visitor enters their email address in a form, do not use it as the sender's address for the message. Use the authenticated email address as the sender, and then add the visitor's address as the reply-to address.

Example:

$mail->Username = 'sender@domain.xyz';
$mail->setFrom('sender@domain.xyz', 'Website Contact Form');
$mail->addReplyTo($visitor_email);

This configuration allows you to reply to the visitor from your email account without sending the message with an unauthorized sender address.

 

Temporarily enable debug mode

In case of an error, temporarily enable PHPMailer's debug mode to obtain more details about the SMTP connection:

$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';

Disable this mode after your tests to avoid displaying technical information to website visitors.

 

Learn more

Link naar deze veelgestelde vragen: https://faq.infomaniak.com/576


Is deze veelgestelde vragenlijst nuttig geweest?