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: firstname.lastname@example.org, 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 email@example.com, 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 = "firstname.lastname@example.org"; $subject = "Test mail"; $message = "This is a test message."; $headers = ; $headers = "From: email@example.com"; $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: firstname.lastname@example.org"; $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.