Help- drupal never sends mail

ramdak5000@www.... - February 20, 2005 - 01:16

I have a Drupal install that works perfectly except that it never sends out an email when an user is added by the admin or self-registered.

I seem to have all the necessary modules turned on, so this is very frustrating for me and is delaying the launch of my site.

Please let me know if I am missing something?

It could be the host configuration

kbahey - February 20, 2005 - 02:06

It could be the hosting configuration. I mean, how the hosting company configured the host.

Try to troubleshoot it outside Drupal first, with a PHP script

Change the email address below, and put the following code in a file called testmail.php in your public_html (or www) directory. Then point your browser to http://example.com/testmail.php

<?php
// The message
$message = "Line 1\nLine 2\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

// Send
$rc = mail('your-email-address@example.com', 'Test Subject', $message);

if (
$rc) {
  print
"Mail successfully sent!<br>";
}
else {
  print
"Failed to send mail<br>";
}
?>

You could try more examples from here:

http://www.php.net/manual/en/function.mail.php

Thanks...

ramdak5000@www.... - February 20, 2005 - 04:04

That was very helpful. I put testmail.php is on the same domain on which I am using Drupal to develop the site. Mail worked successfully and I actually received it.

But the problem with Drupal still continues. Is there anything else that could be wrong?

Is there an error in the log?

kbahey - February 20, 2005 - 14:12

Hmmm. So it is a Drupal issue. Or the mail server on your hosting machine, or your own receiving mail server are picky about what addresses you can send from.

Here are a few things to check:

1. From the admin menus, check the logs.

Is there an error about being unable to send email to users? Or is it silent?

2. Another thing to try is pasting this code snippet into a node of type PHP, then paste the output you get when accessing the node here:

<?
$from = variable_get('site_mail', ini_get('sendmail_from'));
print "From: $from
";

$subject = "test subject";
$body = "This is a test\nThis is a test\This is a test\n";
$headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
$rc = user_mail($account->mail, $subject, $body, $headers);
if ($rc) {
print "Success
";
}
else {
print "Failed
";
}
?>

This is taken from user.module, and will use the function user_mail from that module, but with more description on what is going on.

Give it a try and paste the results here in this thread.

Sorry I lost track of this

ramdak5000@www.... - February 27, 2005 - 12:48

Sorry I lost track of this thread.

I will try out the things you have suggested and post back.

Sorry to bring up this up

ramdak5000@www.... - March 9, 2005 - 15:01

Sorry to bring up this up again, but I tried the code snippet and it returned 'Success'.

Someone also suggested checking the "SMTP settings in the php.ini file on the server" in the following thread: http://drupal.org/node/5332

I didn't do this, but checked the phpinfo() file on my server. It shows the following for local value and master value respectively:

sendmail_from me@localhost.com me@localhost.com
sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i
SMTP localhost localhost

Any suggestions?

Incidentally, my hosting account and the database serving Drupal are on different servers. Does this matter?

Thanks

smtp server

matt westgate - March 9, 2005 - 15:16

Some hosting companies disable the use of the mail() function when sending email to other domains, thus you may have to pass mail directly to the smtp server.

Follow the instructions in this README.txt file and let us know if that solved the problem.

Thank you very much, I was

ramdak5000@www.... - March 9, 2005 - 15:29

Thank you very much, I was unaware of this trick.

I followed the instructions in the file, returned to Drupal and tested by creating a new user. I got the following message:

"Created a new user account. No e-mail has been sent."

Sigh. Wonder what else is wrong.

Nothing is wrong

matt westgate - March 9, 2005 - 23:50

The message:

"Created a new user account. No e-mail has been sent."

means that Drupal did not send an e-mail to the user since the admin created this account. It doesn't mean that Drupal was unable to send e-mail. To test whether Drupal can send email, logout and request a new password for a user you can check the e-mail of.

Oh! Thanks for the insight.

ramdak5000@www.... - March 10, 2005 - 01:59

Oh! Thanks for the insight. The request password worked even earlier.

However, I signed up to create a new account as a visitor and got the following error message:

Fatal error: Call to undefined function: user_mail_wrapper() in /usr/www/users/ramdak/actfordharma/development/modules/user.module on line 338

My setting is configured to 'Visitors can create accounts and no administrator approval is required', although the original setting was that only the admin could add accounts.

Thanks

smtp.inc

matt westgate - March 10, 2005 - 03:23

Try removing the

$conf["smtp_library"] = "includes/smtp.inc";

line in your configuration file.

i am having the same problem

peterw - March 15, 2005 - 03:39

i am having the same problem although getting rid of the line in the config file does not work. any other suggestions?

I finally figured out that

ramdak5000@www.... - March 15, 2005 - 08:42

I finally figured out that there is not much of a problem with the mail functions in Drupal. It seems more a problem with documentation and also a bit with usability design. See this post for a related discussion: http://drupal.org/node/18690

Have you set up your site so that only admins can add accounts? If so, Drupal will never send out a welcome email, although it will add the user and say he/she is authenticated.

Try changing this setting so that visitors can automatically register for an account- the email goes out immediately and everything works instantaneously. This should convince you that the email system in Drupal works, although there may be other issues based on the hosting environment.

You can change the setting by going to administer>users>configure

Let us know if this solves your problem.

it must have been late...

peterw - March 15, 2005 - 15:36

actually, the problem was i didn't properly define the smtp.inc file with that specific function in it. when you download file from the CVS I only got the class.smtp.inc and so there was no function being used. now all i have to do is setup or find an smtp server then the emails will be sent out.

EDIT: btw, the file i should've downloaded is located here: http://cvs.drupal.org/viewcvs/drupal/contributions/tricks/smtp/smtp.inc?...

another way i know it works is that when i try to use non-smtp servers to send my mail i get an error like this:

warning: fsockopen(): unable to connect to localhost:25 in /.../.../.../includes/class.smtp.inc on line 87.

warning: socket_set_timeout(): supplied argument is not a valid stream resource in /.../.../.../includes/class.smtp.inc on line 89.

anyone know of a really easy setup smtp server? preferably a daemon too because i have tried ssmtp, esmtp, nbsmtp. maybe i did somethin wrong there too.

thanks.

smtp & admin account

trantt - December 16, 2005 - 22:33

since i don't have a smtp server on my xp machine, how can i add a 1st user account without sending out a welcome message?

thanks

smtp.module can also solve the problem

jbudisantosa - January 10, 2006 - 17:40

I got the same problem as discussed here and I didn't exactly know why my drupal's site did not send any email to new registered user. Then I downloaded smtp.module and setup drupal's smtp using my username and password at my hosting server (perhaps it can be any valid smtp server but I didn't try).

Aha, it solved the problem.

Warm regards from Indonesia,
/jbudisantosa

yay it works!

sys6x - January 14, 2006 - 15:32

thanks dude, I finally got it working =)

Thanks, solved my mailing

noid - January 29, 2006 - 05:20

Thanks, the smtp module solved my mailing problem too. :)

I installed smtp.module, but it didn't solve the problem

ff1 - February 15, 2006 - 14:30

I installed smtp.module, but it didn't solve the problem.

I've started a new thread with my specific problems here http://drupal.org/node/49513. Any help will be greatly appreciated.

ian

hmm same problem here but

jorisx - June 14, 2007 - 18:37

hmm same problem here but now with drupal 5.1
i've used the code

<?
$from = variable_get('site_mail', ini_get('sendmail_from'));
print "From: $from
";

$subject = "test subject";
$body = "This is a test\nThis is a test\This is a test\n";
$headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from";
$rc = user_mail($account->mail, $subject, $body, $headers);
if ($rc) {
print "Success
";
}
else {
print "Failed
";
}
?>

but i get only a blank page with: From: info@toppop.nl ...

Http://www.reloadmedia.com

drupal_mail

ff1 - July 12, 2007 - 15:38

As of drupal 5, user_mail has been replaced with drupal_mail.

ian
Fantasy Formula 1

hi

abhilasha bhardwaj - July 2, 2008 - 10:59

Sorry wrongly posted here but it is the reference for comment no 1 of this forum by Kbahey. I go though this forum and try your suggestion it shows me "fail to send" (when placed in the public directory) could u please tell me exactly which modules are needed for sending an email. i am working on drupal 6.2.

it is showing this error:-

mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\drupal-6.2\includes\common.inc(1537) : eval()'d code on line 9.

SAME PROBLEM

P3T3R - June 15, 2005 - 20:24

I have the same problem like Peterw, Drupal return me an error of class.smtp.inc, the user was created but drupal cna't send mail.

Any solutions???

warning: main(includes/class.smtp.inc): failed to open stream: No such file or directory in /home/www/includes/smtp.inc on line 3.
warning: main(): Failed opening 'includes/class.smtp.inc' for inclusion (include_path='.:/usr/local/lib/php') in /home/www/includes/smtp.inc on line 3.

Fatal error: Undefined class name 'smtp' in /home/www/includes/smtp.inc on line 26

if someone can solved this PROBLEM

irek - March 29, 2006 - 09:15

if someone can solved this PROBLEM

Response Edited - Problem Solved

formadmirer - May 31, 2006 - 16:33

Installed SMTP module and with some minor configuration of our mail server - voila - problem solved.

I installed drupal and I

holydrupal - October 11, 2007 - 20:17

I installed drupal and I couldn't send emails, I checked with the isp and my hosting provider and everything is fine.
I test the php test expamle script and it was successful too.

I installed SMTP dev version for 5.2 and my problem solved,
any idea what caused default api of drupal mail not working in my website?

Emails not sending - error message from php node

Kimster - May 13, 2008 - 09:57

I got this error message when adding the php to a node:

From: postmaster@mysite.co.uk
Fatal error: Call to undefined function user_mail() in /home/fhlinux169/c/mysite.co.uk/user/htdocs/includes/common.inc(1347) : eval()'d code on line 9

Have been going round in circles with this - this is what my host(Streamline) say:

"This issue is occuring because there is a missing fifth parameter in your mail script. This has always been a requirement of mail scripts on our shared hosting platform but recent updates to our Linux servers (from PHP4 to PHP5) has meant that this is now always required."

I have tested the testmail.php and it works and emails arrive.

Will this be fixed if I install the SMTP Module?

added fifth parameter - now works

Kimster - May 14, 2008 - 07:36

In file: common.inc

Line: 1937

Changed:
function drupal_mail($mailkey, $to, $subject, $body, $from = NULL, $headers = array()) {

To:
function drupal_mail($mailkey, $to, $subject, $body, $from = "mysite.com", $headers = array()) {

:(

4vinoth - May 29, 2008 - 15:42

HI Kimster

Could you please let us know how you fixed this?

I have added that additional parameter, but no luck. :(

Ah, Forgot to tell that, We are also using Streamline!!!!

Do you using SMTP Module?

Vinoth

Hi 4vinoth, Sorry for late

Kimster - June 12, 2008 - 14:57

Hi 4vinoth,

Sorry for late reply - I missed this one.

Maybe you have already sorted?

The other thing I came up against was maybe the emails are getting caught as spam - try a few different addresess, I believe this can be a problem with new domains.

I don't use SMTP.

NO Luck :(

4vinoth - July 5, 2008 - 15:25

Thank You for the reply

வினோத்

 
 

Drupal is a registered trademark of Dries Buytaert.