Send email PHP e CPANEL - Email authentication

Asked

Viewed 759 times

1

What is the right way to send an email using PHP. This email will be authenticated?

1 answer

5

I had to learn this to implement in a project, I did not find any tutorial that explained everything well so I leave here what to do.

If you like, upvote for more people to see.

Notes: 1 - In the code you can only put Sender to end in '@dominio_do_site.com' 2 - Services like Hotmail can put emails not properly authenticated in the trash folder.

When receiving the Email sent the email services (gmail..) can give several problems:

Problem 1: Gmail, warns the recipient who can’t verify that the email was actually sent by the email specified in 'Sender'.

inserir a descrição da imagem aqui

Solution: In order not to have this "error" you have to go to the C-Panel go to email authentication>email authentication and activate both DKIM and SPF. In this part if you have any problem, when contacting your hosting service you should be able to find a solution. But in principle just click on two buttons.

Problem 2: Next to the email specified in the code to appear on Sender, you can see the email server that actually sent the email. Example: "via io.wv.pt" Io.wv.pt being the email server, which varies depending on the company hosting the website.

Solution:

In the code it is necessary to use headers and other parameters and not only the basic.

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 as they wish in terms of formatting. I consider that the core is good)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.