Like many of us, I am also facing an issue with sending emails from Drupal website hosted on Linux Host. From my tests I found that -
1) I can send and receive emails by accessing webmail of the domain's email account.
2) But when sending email using the contact from on the website, Drupal says email is sent successfully but emails are not received. Nor are the emails visible in the "Sent" box in webmail. The same email was configured on the site as well as contact form settings.
The error thrown by Drupal is as shown above:
Incidentally, I also tested on a WordPress site and even emails are not getting sent from WordPress's Contact Form 7 plugin.
So I ruled out Drupal as the issue or WordPress for that matter. It seems to me that it could be the host that is not allowing the emails to be sent. So I contacted my service provider.
And, here is the reply from my hosting service provider:
We would like to update you that Mail function is disabled on the server because it is a vulnerable function and can be used by spammers to sendunauthenticated emails.Using the php mail function means that you are sending emails without even login into your email account.
To know more about why we have disabled mail function, please follow the link as given here : https://lwn.net/Articles/8653/
There is a workaround for that. You can use smtp authentication in your mailing scripts to send emails. So disabling mail function should not cause problems.
If you are using our mailing services then you can use below smtp authentication based sample script:
============================================
< ?php
require_once "Mail.php";
$from = "Test <abc@xyz.com>";
$to = "<exampleid@gmail.com>";
$subject = "Feedback messgae using PHP SMTP with SSL\r\n\r\n";
$body = "Feedback Message";
$host = "ssl://serverhsotname.cloudhostdns.net";
$port = "465";
$username = "abc@xyz.com";
$password = "Bima.815"; //Password of this mail id
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
============================================
If you are using any plugin or contact form, use the below details:
----------------------
smtp host : serverhostname.cloudhostdns.net
smtp port: 465
type: ssl
smtp user: Your mail id which you want to use.
smtp password: password of this mail id.
-----------------------
Regarding Mail.php file, it is a PEAR package which is already installed on server. You only need to include it in your PHP script.
============================================
The link the support provided https://lwn.net/Articles/8653/ goes to a post with title - "PHP: vulnerabilities in the mail() function".
I am planning to implement the solution they suggested in the coming days. If you have had similar issues and were able to resolve it, then kindly do share links or in the comment below.
UPDATE:
Resolved: Drupal unable to send emails using the contact forms [a host issue]
Solution: How to resolve Drupal unable to send email - contact the site administrator?
1) I can send and receive emails by accessing webmail of the domain's email account.
2) But when sending email using the contact from on the website, Drupal says email is sent successfully but emails are not received. Nor are the emails visible in the "Sent" box in webmail. The same email was configured on the site as well as contact form settings.
The error thrown by Drupal is as shown above:
"Unable to send email. Contact the site administrator if the problem persists..
Incidentally, I also tested on a WordPress site and even emails are not getting sent from WordPress's Contact Form 7 plugin.
So I ruled out Drupal as the issue or WordPress for that matter. It seems to me that it could be the host that is not allowing the emails to be sent. So I contacted my service provider.
And, here is the reply from my hosting service provider:
We would like to update you that Mail function is disabled on the server because it is a vulnerable function and can be used by spammers to sendunauthenticated emails.Using the php mail function means that you are sending emails without even login into your email account.
To know more about why we have disabled mail function, please follow the link as given here : https://lwn.net/Articles/8653/
There is a workaround for that. You can use smtp authentication in your mailing scripts to send emails. So disabling mail function should not cause problems.
If you are using our mailing services then you can use below smtp authentication based sample script:
============================================
< ?php
require_once "Mail.php";
$from = "Test <abc@xyz.com>";
$to = "<exampleid@gmail.com>";
$subject = "Feedback messgae using PHP SMTP with SSL\r\n\r\n";
$body = "Feedback Message";
$host = "ssl://serverhsotname.cloudhostdns.net";
$port = "465";
$username = "abc@xyz.com";
$password = "Bima.815"; //Password of this mail id
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
============================================
If you are using any plugin or contact form, use the below details:
----------------------
smtp host : serverhostname.cloudhostdns.net
smtp port: 465
type: ssl
smtp user: Your mail id which you want to use.
smtp password: password of this mail id.
-----------------------
Regarding Mail.php file, it is a PEAR package which is already installed on server. You only need to include it in your PHP script.
============================================
The link the support provided https://lwn.net/Articles/8653/ goes to a post with title - "PHP: vulnerabilities in the mail() function".
I am planning to implement the solution they suggested in the coming days. If you have had similar issues and were able to resolve it, then kindly do share links or in the comment below.
UPDATE:
Resolved: Drupal unable to send emails using the contact forms [a host issue]
Solution: How to resolve Drupal unable to send email - contact the site administrator?
Comments
Post a Comment