Knowledge base

1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!

Using PHPMailer on Infomaniak

Update 06/30/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. This guide is therefore provided for informational purposes only, and its implementation remains your responsibility (ref.: Support Policy / Art. 11.9 of the Terms of Service). If needed, a qualified professional can assist you.


 

Introduction

  • PHPMailer is a PHP library that allows you to create and send emails from a website, particularly via SMTP.
  • It allows you, in particular, 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 site must be compatible with a recent encrypted connection, including 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 maintained 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 or install it with Composer if your project uses it.
  2. Copy the PHPMailer files into a directory on your website via FTP.
  3. Load the necessary files into your PHP script, adapting the path according to the location chosen:

    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 {
// Configuration SMTP
$mail->isSMTP();
$mail->Host       = 'mail.infomaniak.com';
$mail->SMTPAuth   = true;
$mail->Username   = '[sender@domain.xyz](mailto:sender@domain.xyz)';
$mail->Password   = 'mot_de_passe_de_l_adresse_mail';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port       = 465;
$mail->CharSet    = 'UTF-8';

```
// Expéditeur
// L'adresse doit correspondre à celle utilisée pour l'authentification SMTP.
$mail->setFrom('sender@domain.xyz', 'Nom du site');

// Destinataire
$mail->addAddress('recipient@example.com');

// Adresse de réponse facultative
$mail->addReplyTo('sender@domain.xyz', 'Nom du site');

// Contenu du message
$mail->isHTML(true);
$mail->Subject = 'Message envoyé depuis le site';
$mail->Body    = '<p>Contenu HTML du message.</p>';
$mail->AltBody = 'Contenu texte du message.';

$mail->send();
echo 'Message envoyé';
```

} catch (Exception $e) {
echo 'Le message n’a pas pu être envoyé. Erreur: ' . 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 PHPMailer version used by your project;
  4. the correspondence between the SMTP port and the chosen encryption.

For reliable configuration, use a recent version of PHP, compatible with TLS 1.2 or higher, as well as a current version of PHPMailer. Consult these guides if necessary:

 

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', 'Nom du site');

In this example, the script authenticates with sender@domain.xyz, but attempts to send the message with 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', 'Nom du site');

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

Case of a contact form

If a visitor enters their email address in a form, do not use it as the sender address of 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', 'Formulaire du site');
$mail->addReplyTo($email_visiteur);

This configuration allows you to reply to the visitor from your email software 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


Has this FAQ been helpful?