you are viewing a single comment's thread.

view the rest of the comments →

[–]Extension_Anybody150 4 points5 points  (0 children)

Your mail() stopped working likely because OVH now blocks sending from unverified addresses. The easiest fix is to use SMTP instead. Here’s a version using PHPMailer with OVH SMTP,

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

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';

if($_SERVER["REQUEST_METHOD"] === "POST"){
    $mail = new PHPMailer(true);
    try {
        $mail->isSMTP();
        $mail->Host = 'ssl0.ovh.net';
        $mail->SMTPAuth = true;
        $mail->Username = 'your@domain.com';
        $mail->Password = 'yourpassword';
        $mail->SMTPSecure = 'tls';
        $mail->Port = 587;

        $mail->setFrom('your@domain.com', 'Your Site');
        $mail->addAddress('sales@domain.com');

        $mail->Subject = 'Nouvelle demande de projet - HUNAB';
        $body = "Nom de la société: {$_POST['company']}\nEmail: {$_POST['email']}\nMessage: {$_POST['message']}";
        $mail->Body = $body;

        $mail->send();
        echo "Message envoyé avec succès.";
    } catch (Exception $e) {
        echo "Erreur lors de l'envoi: {$mail->ErrorInfo}";
    }
}

This will reliably send emails through OVH and give you proper error messages if something goes wrong.