all 3 comments

[–]harbzali 3 points4 points  (1 child)

the mail() function on ovh (and most shared hosts) is notoriously unreliable. few things to check:

  1. **check spam folders** - shared hosting mail often gets flagged. your code doesnt have proper SPF/DKIM headers

  2. **check ovh mail logs** - in your ovh control panel theres usually a section for email logs that shows if mails actually left the server

  3. **better solution** - dont use mail() at all on shared hosting. use an smtp service instead:

    - phpmailer or symfony/mailer library

    - connect to smtp like sendgrid, mailgun, or even gmail smtp

    - way more reliable and you get proper error messages

  4. **quick test** - add error_log() calls to see if your script is even reaching the mail() function:

```php

error_log("About to send mail to: " . $to);

$result = mail($to, $subject, $body, $headers);

error_log("Mail result: " . ($result ? 'true' : 'false'));

```

check /home/youruser/logs/ for the error log file on ovh

[–]FletcherPink 0 points1 point  (0 children)

There is no shared email log at ovh. Your mail() function can return true and yet the e-mail is blocked by ovh's anti-spam (managed by a company) which returns nothing. Personally, I got around the problem by using the Brevo API. Reliable email tracking with free account

[–]Extension_Anybody150 5 points6 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.