Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
That means the mail is trying to be sent thanks to the localhost. But ovh provide a specific domain for mailing : smtp.mydomain.com
. So you will have to use ini_set()
since you can't change the php.ini
on shared host :
ini_set("SMTP", "smtp.mydomain.com");
ini_set("sendmail_from", "postmaster@mydomain.com");
$headers ='From: postmaster@my_domain.com'."\n";
$headers .='Reply-To: postmaster@my_domain.com'."\n";
$headers .='Content-Type: text/plain; charset="iso-8859-1"'."\n";
$headers .='Content-Transfer-Encoding: 8bit';
if (
mail(
'valid_destination_adress@gmail.com',
'test mail',
'Message of the mail',
$headers
)
){
echo 'ok';
} else {
echo 'erreur';
}
echo "Check your email now....<br/>";
But I would recommand to use a library for this, such as SwiftMailer, or PHPMailer