I deployed a Drupal 8 website, on a hosting service with cPanel, with domain mydomain.com.
If I set this email address on the user profile: email@example.com, that is an email address with a domain different from mydomain.com, then I go to:
and I click to "Send" trying to receive the "reset password" email, it give me the error below and I don't receive the email:
Unable to send e-mail. Contact the site administrator if the problem persists.
Same problem on contact forms.
If I set an email address within my domain, for example firstname.lastname@example.org, all works and the email is correctly sent.
Any idea why this is happening and how to solve this problem?
I tried to create this php script inside the server in order to check if there is some issue on the server configuration:
<?php $to = "email@example.com"; $subject = "Test mail"; $message = "This is a test message."; $headers = ; $headers = "From: firstname.lastname@example.org"; $headers = "MIME-Version: 1.0"; $headers = "Content-type: text/plain; charset=UTF-8; format=flowed; delsp=yes"; $headers = "Content-Transfer-Encoding: 8Bit"; $headers = "X-Mailer: Drupal"; $headers = "Reply-To: email@example.com"; $res = mail($to, $subject, $message, implode("\n", $headers)); echo "Mail Sent. <br/>\n"; echo "Res: " . $res . " <br/>\n";
When I run this script it correctly works and sends the email, either if the
$to property is from my domain or if it is from an external domain.
So I excluded it is a server configuration issue.