-3

I am Dylane, and I have a trouble with my PHP code for sending an email. The code succeeded to send an email just to certain mail addresses, but does not send to the other (by example: Gmail, outlook, yahoo, etc.).

Can someone advise?

Here's my code:

    <?php
$mail = 'my@domain.com'; // email.
if (preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $mail))
{
    $passage_ligne = "\r\n";
}
else
{
    $passage_ligne = "\n";
}
//===== HTML format.
$message_txt = "TEXT goes here!";

$message_html = "<html><head></head><body> HTML TEXT</body></html>";
//==========

//=====Creation of Création de la boundary
$boundary = "-----=".md5(rand());
//==========

//=====Subject defination.
$sujet = "Some subject";
//=========

//=====Header creation.
$header = "From: \"Something\"<my@domain.com>".$passage_ligne;
$header.= "Reply-to: \"Something\" <my@domain.com>".$passage_ligne;
$header.= "MIME-Version: 1.0".$passage_ligne;
$header.= "Content-Type: multipart/alternative;".$passage_ligne." boundary=\"$boundary\"".$passage_ligne;
//==========

//=====Creation of message.
$message = $passage_ligne."--".$boundary.$passage_ligne;
//=====Ajout du message au format texte.
$message.= "Content-Type: text/plain; charset=\"ISO-8859-1\"".$passage_ligne;
$message.= "Content-Transfer-Encoding: 8bit".$passage_ligne;
$message.= $passage_ligne.$message_txt.$passage_ligne;
//==========
$message.= $passage_ligne."--".$boundary.$passage_ligne;
//=====Ajout du message au format HTML
$message.= "Content-Type: text/html; charset=\"ISO-8859-1\"".$passage_ligne;
$message.= "Content-Transfer-Encoding: 8bit".$passage_ligne;
$message.= $passage_ligne.$message_html.$passage_ligne;
//==========
$message.= $passage_ligne."--".$boundary."--".$passage_ligne;
$message.= $passage_ligne."--".$boundary."--".$passage_ligne;
//==========

//=====Send email.
mail($mail,$sujet,$message,$header);
//==========

header('location:../index.php');
?>
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

If you want to reliably deliver email then you should set up the MX, RDNS and SPF records for the ip adress of the server from which you are sending out the emails. Without these records most recipient mail servers will treat these emails as spam.