Jump to content

PHP: Email did not reach some recipient


pascal_22

Recommended Posts

Hello,

 

SOrry for my english, i ll try to do my best.

 

so far I was using the mail () function to send emails to members of my site. Like this site, when a member registers on my site, he must confirm his email. However only 30% confirmed. I receive message via my contact form as what they do not receive my confirmation email.

I came across a tutorial on PHPMAIL ()

Do you think PHPMAIL be paid part of the problem?

 

I website is under a dedicated server.

In my mail, i use HTML, with table, <h><p>.... Is it better use onluy text? I also have link.

 

Thanks a lot for your help!

Link to comment
Share on other sites

Hello,

thanks

 

but i mean it's over 60% of new register didnot receive my confirmation message because they let me know via my contact form, so i have to send it manually with my personnel email, with this, they receive it.

 

I send email only with html format, should i send it with no html? only text

 

With PHPMAILER , i saw that we can set '$mailer->AltBody=$textBody;' is for when user did not accept HTML, it will display text only

 

Is it a good Start?

Link to comment
Share on other sites

thanks!!

They say nothing is spam folder too...

 

here my code!

 

$Title = "Welcome on mydomain name";

 

$headers ='From: <contact@mydomainname.com>'."\n";

$headers .='Reply-To: contact@mydomainname.com'."\n";

$headers .='Content-Type: text/html; charset="iso-8859-1"'."\n";

$headers .='Content-Transfer-Encoding: 8bit';

 

$body= "<html><head><style type=\"text/css\">a.link{margin-top:20px;font-family: arial;font-size: 20px;color:#336699;}</style></head>";

$body= $body. "<body>my message with link, h , p,  table";

$body=$body."</body></html>";

$Email=user email;

mail($Email, $Title , $body, $headers );

 

Maybe it can help you!

Thanks

 

Link to comment
Share on other sites

thanks!!

They say nothing is spam folder too...

 

here my code!

 

$Title = "Welcome on mydomain name";

 

$headers ='From: <contact@mydomainname.com>'."\n";

$headers .='Reply-To: contact@mydomainname.com'."\n";

$headers .='Content-Type: text/html; charset="iso-8859-1"'."\n";

$headers .='Content-Transfer-Encoding: 8bit';

 

$body= "<html><head><style type=\"text/css\">a.link{margin-top:20px;font-family: arial;font-size: 20px;color:#336699;}</style></head>";

$body= $body. "<body>my message with link, h , p,  table";

$body=$body."</body></html>";

$Email=user email;

mail($Email, $Title , $body, $headers );

 

Maybe it can help you!

Thanks

 

 

Do you literally have

 

$Email=user email;

 

in your code?  Or did you just put that there for some reason?  Is this the exact code you have in place?

 

Your $body variables are overwriting eachother in every instance.  You need to change to:

 

$body .= 

 

For each after the declaration.

Link to comment
Share on other sites

Hello,

Thanks!

 

This is not the same :

$body=$body."other message" and $body.="other message"

I thought it was the same.

 

$Email=user email;

I change it because it a variable in my function. so the exact code is :$Email=$vEmail;

 

It's the exact code but i just change my domain name. Because so forum don't like it when we put our website address!

 

Link to comment
Share on other sites

Ok good!

here is the relevant code

 

 

function SendEmail($vEmail)

{

        GET USERNAME AND PASSWORD OF THIS USER TO INCLUDE IT IN EMAIL

        ...i open my database connection

        $Result=mysql_query("select * from TblUsers where Email='$vEmail'");

 

$nb=mysql_numrows($Result);

        while($row = mysql_fetch_row($Result))

{

$NomUsager = $row[1];

$MDP = $row[2];

                }

$Sujet = "<html><head><style type=\"text/css\">td.EnvoiParEmailTitre{margin-top:20px;font-family: arial;font-size: 20px;color:#336699;}td.EnvoiParEmailText{font-family: arial;font-size: 16px;} td.EnvoiEmailInfosConnexion{font-family:arial;font-size: 16px; text-decoration:underline;}</style></head>";

$Sujet = $Sujet . "<body>";

 

 

$Sujet = $Sujet . "<table style=\"margin-bottom: 20px;\"><tr><td class=\"EnvoiParEmailText\" style=\"font-family: arial;font-size: 16px;\">Cliquer pour confirmer votre courriel.</td></tr></table>";

 

$Sujet = $Sujet . "<table style=\"margin-bottom:20px;border:1px dotted #d3d3d3;\">

<tr>

<td style=\"font-family: arial;font-size: 17px;padding:10px 5px 10px 5px;\">

<table cellspacing=0 cellpadding=0 style=\"margin-bottom: 0px;\">

<tr>

<td class=\"EnvoiEmailInfosConnexion\" style=\"font-family:arial;font-size: 16px; text-decoration:underline;\">Voici vos informations de connexion:</td>

</tr>

<tr>

<td class=\"EnvoiParEmailText\" style=\"font-family: arial;font-size: 16px;\">Nom d'usager: $NomUsager</td>

</tr>

<tr>

<td class=\"EnvoiParEmailText\" style=\"font-family: arial;font-size: 16px;\">Mot de passe: $MDP</td>

</tr>

</table>

</td>

</tr>

</table>";

 

$Sujet = $Sujet . "<table style=\"margin-bottom: 20px;\"><tr><td class=\"EnvoiParEmailText\" style=\"font-family: arial;font-size: 16px;\">Vous pouvez accéder directement au site en cliquant sur le lien <a href='http://www.mydomaine.com'>http://www.mydomain.com</a></td></tr></table>";

 

$Sujet = $Sujet . "</body></html>";

$Email=$vEmail;

mail($Email, $Title , $body, $headers );

}

Link to comment
Share on other sites

function SendEmail($vEmail)

{

        GET USERNAME AND PASSWORD OF THIS USER TO INCLUDE IT IN EMAIL

        ...i open my database connection

        $Result=mysql_query("select * from TblUsers where Email='$vEmail'");

 

  $nb=mysql_numrows($Result);

        while($row = mysql_fetch_row($Result))

      {

        $NomUsager = $row[1];

        $MDP = $row[2];

                }

        $Title= "$NomUsager Votre mot de passe sur mydomain.com";

 

$headers ='From: "Mywebsite"<contact@mydomaine.com>'."\n";

$headers .='Reply-To: contact@mydomaine.com'."\n";

$headers .='Content-Type: text/html; charset="iso-8859-1"'."\n";

$headers .='Content-Transfer-Encoding: 8bit';

        $Sujet = "<html><head><style type=\"text/css\">td.EnvoiParEmailTitre{margin-top:20px;font-family: arial;font-size: 20px;color:#336699;}td.EnvoiParEmailText{font-family: arial;font-size: 16px;} td.EnvoiEmailInfosConnexion{font-family:arial;font-size: 16px; text-decoration:underline;}</style></head>";

        $Sujet = $Sujet . "<body>";

         

     

        $Sujet = $Sujet . "<table style=\"margin-bottom: 20px;\"><tr><td class=\"EnvoiParEmailText\" style=\"font-family: arial;font-size: 16px;\">Cliquer pour confirmer votre courriel.</td></tr></table>";

 

        $Sujet = $Sujet . "<table style=\"margin-bottom:20px;border:1px dotted #d3d3d3;\">

                          <tr>

                              <td style=\"font-family: arial;font-size: 17px;padding:10px 5px 10px 5px;\">

                                <table cellspacing=0 cellpadding=0 style=\"margin-bottom: 0px;\">

                                    <tr>

                                      <td class=\"EnvoiEmailInfosConnexion\" style=\"font-family:arial;font-size: 16px; text-decoration:underline;\">Voici vos informations de connexion:</td>

                                    </tr>

                                    <tr>

                                      <td class=\"EnvoiParEmailText\" style=\"font-family: arial;font-size: 16px;\">Nom d'usager: $NomUsager</td>

                                    </tr>

                                    <tr>

                                      <td class=\"EnvoiParEmailText\" style=\"font-family: arial;font-size: 16px;\">Mot de passe: $MDP</td>

                                    </tr>                             

                                </table>

                              </td>

                          </tr>

                        </table>";

 

        $Sujet = $Sujet . "<table style=\"margin-bottom: 20px;\"><tr><td class=\"EnvoiParEmailText\" style=\"font-family: arial;font-size: 16px;\">Vous pouvez accéder directement au site en cliquant sur le lien <a href='http://www.mydomaine.com'>http://www.mydomain.com</a></td></tr></table>";

 

        $Sujet = $Sujet . "</body></html>";

$Email=$vEmail;     

mail($Email, $Title, $Sujet , $headers );

}

Link to comment
Share on other sites

This is not the same :

$body=$body."other message" and $body.="other message"

I thought it was the same.

 

I see the concatenation now.  No CODE tags make it difficult to pick up the small things.  Please wrap your code in the

 tags from now on (without the spaces).

 

Don't worry about the translation, please.  All that's doing is throwing people off 'cause the variable names don't line up now as I no longer see where $Title, $body, $headers are being defined in your code.  Also, I don't see where you are calling your SendEmail() function.

 

Edit: I see you put $title and $headers back in there.  For clarity, please just post your code exactly as it is in your script (removing any personal information, of course; but variable names and such need to remain the same).

Link to comment
Share on other sites

SendEmail is call when i validate the username, password and birth date.... i check if this email is already existing in my database.

 

SendEmail($_GET["txtEmail"]);

 

here is the function in code tag

function SendEmail($vEmail)
{
         GET USERNAME AND PASSWORD OF THIS USER TO INCLUDE IT IN EMAIL
        ...i open my database connection
        $Result=mysql_query("select * from TblUsers where Email='$vEmail'");
   
   $nb=mysql_numrows($Result);
        while($row = mysql_fetch_row($Result))
      {
         $NomUsager = $row[1];
         $MDP = $row[2];
                }
        $Title= "$NomUsager Votre mot de passe sur mydomain.com";
         
   $headers ='From: "Mywebsite"<contact@mydomaine.com>'."\n"; 
   $headers .='Reply-To: contact@mydomaine.com'."\n"; 
   $headers .='Content-Type: text/html; charset="iso-8859-1"'."\n"; 
   $headers .='Content-Transfer-Encoding: 8bit'; 
         $Sujet = "<html><head><style type=\"text/css\">td.EnvoiParEmailTitre{margin-top:20px;font-family: arial;font-size: 20px;color:#336699;}td.EnvoiParEmailText{font-family: arial;font-size: 16px;} td.EnvoiEmailInfosConnexion{font-family:arial;font-size: 16px; text-decoration:underline;}</style></head>";
         $Sujet = $Sujet . "<body>";
          
      
         $Sujet = $Sujet . "<table style=\"margin-bottom: 20px;\"><tr><td class=\"EnvoiParEmailText\" style=\"font-family: arial;font-size: 16px;\">Cliquer pour confirmer votre courriel.</td></tr></table>";

         $Sujet = $Sujet . "<table style=\"margin-bottom:20px;border:1px dotted #d3d3d3;\">
                           <tr>
                              <td style=\"font-family: arial;font-size: 17px;padding:10px 5px 10px 5px;\">
                                 <table cellspacing=0 cellpadding=0 style=\"margin-bottom: 0px;\">
                                    <tr>
                                       <td class=\"EnvoiEmailInfosConnexion\" style=\"font-family:arial;font-size: 16px; text-decoration:underline;\">Voici vos informations de connexion:</td>
                                    </tr>
                                    <tr>
                                       <td class=\"EnvoiParEmailText\" style=\"font-family: arial;font-size: 16px;\">Nom d'usager: $NomUsager</td>
                                    </tr>
                                    <tr>
                                       <td class=\"EnvoiParEmailText\" style=\"font-family: arial;font-size: 16px;\">Mot de passe: $MDP</td>
                                    </tr>                              
                                 </table>
                              </td>
                           </tr>
                        </table>";

         $Sujet = $Sujet . "<table style=\"margin-bottom: 20px;\"><tr><td class=\"EnvoiParEmailText\" style=\"font-family: arial;font-size: 16px;\">Vous pouvez accéder directement au site en cliquant sur le lien <a href='http://www.mydomaine.com'>http://www.mydomain.com</a></td></tr></table>";

         $Sujet = $Sujet . "</body></html>";
$Email=$vEmail;      
mail($Email, $Title, $Sujet , $headers );
}

 

Link to comment
Share on other sites

ok i see that you edit the post

 

For the code

if (!mail($Email, $Title, $Sujet , $headers)) {
error_log("Email wasn't sent to: $Email\n", 3, 'email_send_errors.log');
}

 

Should i specify a path( folder name) for email_send_errors.log?

 

Also shoud i continue with the mail function or PHPmailer?

Link to comment
Share on other sites

Can you post the block of code that validates and then calls the SendEmail() function please.

 

You say ~70% of your users are not receiving this email, so that function might not even be getting hit.

 

Also, mysql_numrows() is deprecated.  Consider changing to mysql_num_rows().  Not important at this time, but note it.

Link to comment
Share on other sites

Should i specify a path( folder name) for email_send_errors.log?

 

Not necessary.

 

Also shoud i continue with the mail function or PHPmailer?

 

I don't see any code in what you have posted that tells me you're using PHPMailer.  Are you trying to use PHPMailer?

Link to comment
Share on other sites

No i'm not using PHP mailer but i saw maybe two hours ago a tutorial on this forum for PHPMailer... and i check on google and some php programmer says that it's better to use PHPMailer for somes reason..... you can specify an html message and include a text message, so if user can't read html message, it will display textmessage only...

 

 

Link to comment
Share on other sites

a lot of code!!!!  ;)

 

session_start();
$Verif_user = 1;
$Verif_MotPasse = 1;
$Verif_Email = 1;

$username = $_POST["txtUserName"];
$MotPasse = $_POST["txtMotPasse"];
$MotPasse2 = $_POST["txtMotPasse2"];
$email = $_POST["txtEmail"];
$chkConditions = $_POST["chkConditions"];



$_SESSION["txtUsername"] = $username;
$_SESSION["txtPassword"] = $MotPasse;
$_SESSION["txtPassword2"] = $MotPasse2;
$_SESSION["txtEmail"] = $email;
$_SESSION["chkConditions"] = " checked=1";

$_SESSION["Condition_Majeur"] = "";

$_SESSION["MessageUSerName"] = "";
$_SESSION["MessagePassword"] = "";
$_SESSION["MessageEmail"] = "";

$okCondition = 1;


//sert a savoir si tous les champs sont rempli =1 si pas rempli et 0 pour manque info
$ToutRempli = 1;

if(isset($_POST["txtUserName"]))
{

	if($username == "")
	{
		$_SESSION["MessageUSerName"] = "Entrez un nom d'usager";
		$ToutRempli = 0;
	}
	if(strlen($username) > 26)
	{
		$_SESSION["MessageUSerName"] = "Le nom d'usager choisi est trop long. 25 caractères maximum";
		$ToutRempli = 0;
	}
	$TrouverCarac = TrouverCaracteresInterdit($username);
	if($TrouverCarac == "true")
	{

		$_SESSION["MessageUSerName"] = "Le nom d'usager contient des caractères interdit: point, espace, apostrophe, parenthèse, '+', '&', '%', '#', '<', '>', '[', ']', '{', '}', '^', '|', '!', '~', '/', '`' .   25 caractères maximum";
		$ToutRempli = 0;
	}
	//echo "le result:" . $TrouverCarac;		
	if($MotPasse == "")
	{
		$_SESSION["MessagePassword"] = "Entrez un mot de passe";
		$ToutRempli = 0;
	}
	else if($MotPasse2 == "")
	{
		$_SESSION["MessagePassword"] = "Vous devez confirmer votre mot de passe";
		$ToutRempli = 0;
	}		
	else if($MotPasse != $MotPasse2)
	{
		$_SESSION["MessagePassword"] = "Veuillez entrer le même mot de passe";
		$ToutRempli = 0;
	}

	if($email == "")
	{
		$_SESSION["MessageEmail"] = "Entrez une adresse courriel";
		$ToutRempli = 0;
	}

	if(empty($chkConditions))
	{
		$_SESSION["Condition_Majeur"] = "Vous devez confirmer les conditions";
		$okCondition = 0;
		$ToutRempli = 0;
		$_SESSION["chkConditions"] = "";
	}

	if($ToutRempli == 1)
	{

		// validation
		$okValidation = 1;

		$Verif_user=VerifUser($username);
		if($Verif_user==1)
		{
			$okValidation = 0;
			$_SESSION["MessageUSerName"] = "Le nom d'usager <u><b>" . $username . "</b></u> existe déjà!";
			$_SESSION["txtUsername"] = "";
			$username = "";
		}

		$Verif_userNotEmail=VerifUserNotEmail($username);
		if($Verif_userNotEmail==1)
		{
			$okValidation = 0;
			$_SESSION["MessageUSerName"] = "Le nom d'usager doit-être différent d'un courriel";
			$_SESSION["txtUsername"] = "";
			$username = "";
		}

		$Verif_MotPasse=VerifPassword($MotPasse, $username);
		if($Verif_MotPasse==1)
		{
			$okValidation = 0;
			$_SESSION["MessagePassword"] = "Le mot de passe doit contenir au moin 6 caractères.";
			$_SESSION["txtPassword"] = "";
			$MotPasse = "";
			$_SESSION["txtPassword2"] = "";
			$MotPasse2 = "";
		}
		else if($Verif_MotPasse == 2)
		{
			$okValidation = 0;
			$_SESSION["MessagePassword"] = "Le mot de passe doit-être différent du nom d'usagé.";
			$_SESSION["txtPassword"] = "";
			$MotPasse = "";
			$_SESSION["txtPassword2"] = "";
			$MotPasse2 = "";
		}

		$Verif_Email=VerifEmail($email);
		if($Verif_Email==1)
		{
			$okValidation = 0;
			$_SESSION["MessageEmail"] ="L'adresse courrier <u><b>" . $email . "</b></u> n'est pas valide.";
			$_SESSION["txtEmail"] = "";
			$email = "";
		}
		else if($Verif_Email == 2)
		{
			$okValidation = 0;
			$_SESSION["MessageEmail"] ="L'adresse courriel <u><b>" . $email . "</b></u> existe déjà.";
			$_SESSION["txtEmail"] = "";
			$email = "";
		}
		//SI TOUT EST OK
		if($okValidation == 1)
		{
			if(VerifCourrielsBloquer($email) != 1)
			{
				$Code= TrouverCodeAleatoire(10);
                                       // [b]SAVE USER TYO DATABASE[/b]
				$OkEnregist=EnregistrementUSer($username, $MotPasse, $email, $Code);
				if($OkEnregist==1)[b]user is save in database so i send conformation email[/b]
				{
					//EnvoiEmailConfirmation($username, $MotPasse, $email);
					RecupInfos($username, $MotPasse);
					$_SESSION["MessageInscrip_OK"] = "Inscription terminé. Vous pouvez maintenant vous <a href=\"main.php?section=a1SeConnecter\">connecter!</a>";
					unset($_SESSION['MessageUSerName']);
					unset($_SESSION['MessagePassword']);
					unset($_SESSION['MessageEmail']);
					//unset($_SESSION['MessageInscrip_OK']);
					unset($_SESSION['txtUsername']);
					unset($_SESSION['txtPassword']);
					unset($_SESSION['txtEmail']);
					unset($_SESSION['Condition_Majeur']);
					unset($_SESSION['checkedMajeur']);
					unset($_SESSION['checkedCondition']);
					//header("Location: Inscription2.php");
					SendEmail($_POST["txtEmail"]);
					header("Location: Confirmation-Courriel.php");

				}
				else
				{
					$_SESSION["MessageInscrip_OK"] = "<div class=\"divMsgError\"><table width=\"100%\" height=\"100%\" border=0 cellspacing=0><tr><td align=\"center\" valign=\"center\"><img src=\"Images/Cadres/X.png\"></td><td align=\"left\" valign=\"center\" style=\"padding-left:10px;\" class=\"MsgErrorText\">L'inscription ne s'est pas éffectuer. Une erreur s'est produite</td></tr></table></div>";
					header("Location: Inscription.php");

				}
			}
			else
			{
					$_SESSION["MessageEmail"] = "Votre courriel figure parmis les courriels bloqués. Vous pouvez me contacter via la section 'Aide' pour de plus amples informations";

					header("Location: Inscription.php");				
			}
		}
		else
		{
			header("Location: Inscription.php");

		}
	}
	else
	{


		header("Location: Inscription.php");

	}
}


?>

Link to comment
Share on other sites

You really need to start logging your conditions.  What I mean is, if any of your ELSE statements are hit, you'll never know.  For all you know right now, those 70% of users who think an email is being dispatched are actually waiting for nothing since your code messed up somewhere.

 

So, for each of your ELSE statements, add the following error_log() code and add relevant messages so you know where in the code things are messing up.  For example:

 

if ($OkEnregist==1) {
//EnvoiEmailConfirmation($username, $MotPasse, $email);
RecupInfos($username, $MotPasse);
$_SESSION["MessageInscrip_OK"] = "Inscription terminé. Vous pouvez maintenant vous <a href=\"main.php?section=a1SeConnecter\">connecter!</a>";
unset($_SESSION['MessageUSerName']);
unset($_SESSION['MessagePassword']);
unset($_SESSION['MessageEmail']);
//unset($_SESSION['MessageInscrip_OK']);
unset($_SESSION['txtUsername']);
unset($_SESSION['txtPassword']);
unset($_SESSION['txtEmail']);
unset($_SESSION['Condition_Majeur']);
unset($_SESSION['checkedMajeur']);
unset($_SESSION['checkedCondition']);
//header("Location: Inscription2.php");
SendEmail($_POST["txtEmail"]);
header("Location: Confirmation-Courriel.php");

}
else {
error_log('$OkEnregist is 0; File: '. __FILE__ .'; Line: '. __LINE__ ."\n", 3, 'email_send_errors.log');
$_SESSION["MessageInscrip_OK"] = "<div class=\"divMsgError\"><table width=\"100%\" height=\"100%\" border=0 cellspacing=0><tr><td align=\"center\" valign=\"center\"><img src=\"Images/Cadres/X.png\"></td><td align=\"left\" valign=\"center\" style=\"padding-left:10px;\" class=\"MsgErrorText\">L'inscription ne s'est pas éffectuer. Une erreur s'est produite</td></tr></table></div>";
header("Location: Inscription.php");
}

 

This way, you can check that log file anytime somebody complains about not getting their confirmation email.

Link to comment
Share on other sites

if you need help to undestand my code, don't hésitate, i ll help you?

 

Also, when a user tell me that i doesnt receive my mail, the user exist in my database, so the code really hit this funtion

$OkEnregist=EnregistrementUSer($username, $MotPasse, $email, $Code);
				if($OkEnregist==1)[b]user is save in database so i send conformation email[/b]
				{
					//EnvoiEmailConfirmation($username, $MotPasse, $email);
					RecupInfos($username, $MotPasse);
					$_SESSION["MessageInscrip_OK"] = "Inscription terminé. Vous pouvez maintenant vous <a href=\"main.php?section=a1SeConnecter\">connecter!</a>";
					unset($_SESSION['MessageUSerName']);
					unset($_SESSION['MessagePassword']);
					unset($_SESSION['MessageEmail']);
					//unset($_SESSION['MessageInscrip_OK']);
					unset($_SESSION['txtUsername']);
					unset($_SESSION['txtPassword']);
					unset($_SESSION['txtEmail']);
					unset($_SESSION['Condition_Majeur']);
					unset($_SESSION['checkedMajeur']);
					unset($_SESSION['checkedCondition']);
					//header("Location: Inscription2.php");
					SendEmail($_POST["txtEmail"]);
					header("Location: Confirmation-Courriel.php");

				}

 

So i think the code is good, i think is maybe mail function, or my html body.....

Link to comment
Share on other sites

Ok good,

 

great, i will use the error_log('$OkEnregist is 0; File: '. __FILE__ .'; Line: '. __LINE__ ."\n", 3, 'email_send_errors.log');

 

but in this case, when a user told me that he didn't receive anything... all info(username, password, email) are in the database, so no error occur before $OkEnregist=EnregistrementUSer($username, $MotPasse, $email, $Code); because it's this function who save data in Database...

 

Should i continu send email with HTML?

I use HTML in messag e to make it beautifull... blue font.... some text bigger...

 

What do you think?

If a user can't read html message, what will happen?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.