What is the most correct way to send an email using PHP. Is this email authenticated?
What is the most correct way to send an email using PHP. Is this email authenticated?
I had to learn this to implement a project, I did not find any tutorial that explained everything well so I leave here what to do.
If they like to give upvote for more people to see.
Notes: 1 - In the code you can only put the sender ending in '@ domain_of_site.com' 2 - Services like Hotmail can put the duly authenticated e-mails in the trash folder.
When receiving the sent Email the services of email (gmail ..) can give several problems:
Problem 1: Gmail notifies the recipient that it can not verify that the email was actually sent by the email specified in the sender.
Solution:Tonothavethis"error" you must go to C-Panel go to email > email authentication and enable both DKIM and SPF. In this part if you have any problems, when contacting your hosting service you must get a solution. But in principle just click on two buttons.
Problem 2: Beside the email specified in the code to appear in the sender, the mail server that actually sent the email may appear. Example: "through io.wv.pt" As io.wv.pt is the email server, which varies depending on the company hosting the website.
Solution:
In the code you need to use headers and other parameters, not just the basics.
Code:
<html><head>
<title>Untitled Document</title>
</head>
<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! \nThis is a simple email message.";
$headers = "From: [email protected]";
$headers .= "\r\nReply-To: [email protected]";
$headers .= "\r\nX-Mailer: PHP/".phpversion();
mail($to,$subject,$message,$headers,"-f [email protected]");
echo "Mail Sent.";
?>
</html>
(people edit to ask me how you want in terms of formatting. I think the core is good)