0

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: john.smith@example.com, that is an email address with a domain different from mydomain.com, then I go to:

mydomain.com/user/password

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 john.smith@mydomain.com, all works and the email is correctly sent.

Any idea why this is happening and how to solve this problem?


NOTE

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 = "john.smith@example.com";
$subject = "Test mail";
$message = "This is a test message.";

$headers = [];

$headers[] = "From: noreply@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: noreply@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.

0

I solved the problem.

Taking inspiration from this thread, I figured out that, for some obscure reason, I need to set the email setting under "Administration > Configuration > System > Basic site settings > E-mail address" to an existing email address on my hosting service.

So, I created a new email with cPanel, noreply@mydomain.com, then I setted this email address in the above configuration.

Now seems that all is working perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.