Page 1 of 1

mail() function always go to spam

Posted: 2020-09-06 18:38
by D Oliveira
Hi, can anyone diagnose why this code is always leading this email to spam? is there any alternative to the mail() function that would be better for this purpose?

Thank you.

Code: Select all

								
	$to = $email;
	$subject = $name." - Bem Vindo ao Fitbook";

	$message = "
	<html>
	<head>
	<title>Bem vindo ao Fitbook!</title>
	</head>
	<body>
	<div style='text-align: center'><img style='width: 250px' src='https://fitbookapp.net/fitbook/logon.png?c=9' /></div>
	<table align='center'>
	<p><br/></p>". "\n". "\n". "\n". "\n". "\n"."
	<tr>
	<td align='center'> Olá ".$name.", bem vindo ao Fitbook App!</td>
	</tr>
	<p><br/></p>". "\n" . "
	<tr>
	<td align='center'> Seguem abaixo suas credenciais de acesso: </td>
	</tr>
	</table>
	<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
	<table align='center'>
	<tr>
	<th align='center'>Usuário</th>
	</tr>
	<tr>
	<td align='center'>".$email."</td>
	</tr>
	<p> </p>
	</table>
	<table align='center'>
	<tr>
	<th align='center'>Senha</th>
	</tr>
	<tr>
	<td align='center'>fitbook</td>
	</tr>
	</table>
	<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
	<table align='center'>
	<tr>
	<th align='center'>Acessar App</th>
	</tr>
	<tr>
	<td align='center'>https://fitbookapp.net/fitbook/</td>
	</tr>
	<p> </p>
	</table>
	<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
	<table align='center'>
	<tr>
	<th align='center'>Contato</th>
	</tr>
	<tr>
	<td align='center'>[email protected]</td>
	</tr>
	</table>
	<p> </p>
	<div style='text-align: center'><img style='width: 25px' src='https://fitbookapp.net/fitbook/favicon.png?c=9' /></div>
	</body>
	</html>
	";

	// Always set content-type when sending HTML email
	$headers = "MIME-Version: 1.0" . "\r\n";
	$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

	// More headers
	$headers .= 'From: <[email protected]>' . "\r\n";

	mail($to,$subject,$message,$headers);
	

Re: mail() function always go to spam

Posted: 2020-09-07 09:04
by a.gneady
This is usually a tricky issue to diagnose. I see you're including a FROM header, and the sender domain is fitbookapp.net ... Is the server you're sending the email from serving the contents for that domain? If not, you should add its IP address in a DKIM record in your domain's DNS records.

Another issue. There is a missing space after the colon here:

Code: Select all

$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
Should be:

Code: Select all

$headers .= "Content-type: text/html;charset=UTF-8" . "\r\n";
If the above fixes don't work for preventing flagging the email as spam, you should try to inspect the email headers at the recipient .. there might be a clue to why it got flagged.

Re: mail() function always go to spam

Posted: 2020-09-07 18:15
by D Oliveira
I contacted godaddy support and they magically fixed it lol can't share the exact resolution, but maybe if you have the same problem contacting your hosting might work for you as well :) thanks ahmed

Re: mail() function always go to spam

Posted: 2020-09-08 08:54
by a.gneady
Glad it's fixed now :)