I took me forever to learn, that I could install Drupal (and other PHP apps) locally instead of shelling out money for webhosting. So now I have WAMP installed on my pc -after many years. Installing Drupal 5 was a breeze, since I have done this a few times before on my webhosting account. But the email function does not work locally on my windows xp! It works fine, if I upload Drupal to my paid webhosting account! I am lost, so here is my Q?

Do I need an Email Sever for this to work? or is PHP able to handle email somehow itself?

What Email Sever can I get for Windows, if needed? Open Source maybe?

warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Wamp\www\drupal\includes\common.inc on line 1970.

Thank you, this is my hobby - so please bear with me. However if you need a good dentist, give me a call LOL.

Comments

jsloan’s picture

You can follow his odyssey here:
http://drupal.org/node/92710

Mel55113’s picture

Port 25 is the standard SMTP port used for outgoing mail. The machine you are currently running on is "localhost".

The obvious answer is to install a MTA on your PC. But, before you go to that trouble check with your ISP to make sure that they don't prevent outgoing connections on port 25; many do as a way to minimize exposures to spam. Some, I've been told, are willing to open this port upon request. Unfortunately, I can't recommend a Windows MTA although the Linux world has quite a few, e.g., Postfix.

If your ISP doesn't block outgoing port 25 connections, you could also configure php to use the MTA on your hosting account.

A not so obvious answer is to use your ISP's MTA, the one you use for your normal email. I don't have the details but you'd need to configure php to connect to your normal outgoing server, e.g., username, password, server name.

Hope this helps,
Mel

madhavok’s picture

I spent the last 3 hours muddling through the same thing... here's how I solved it.

If you don't want to set up your own on-site email server, just use your ISP's - has to be the ISP who handles your Internet connection because they're the only ones likely to relay your SMTP for you without SSL (unless you have a buddy who runs an email server who will relay traffic from your IP address.)

1. Figure out what your ISP's SMTP server is called - usually their SMTP server is called something like smtp.yourISPdomain.xxx
2. Open up php.ini using the WAMP systray icon -- click the WAMP icon > Config files > php.ini
3. Find the line that looks something like this (use Edit > Find if you need to, but it's about halfway down the page)...

[mail function]
; For Win32 only.
SMTP = localhost

and change it to...

[mail function]
; For Win32 only.
SMTP = smtp.yourISPdomain.xxx (or whatever the server is called)

4. You might want to change the line below that ("sendmail_from") to the email address you normally use.
5. Save the file, close it, click the WAMP systray icon again, and choose Restart All Services
6. Try it again.

I myself ran into another obscure problem that I believe was caused by my ISP who happens to use qmail. I'll post a solution here in case someone is browsing the forums for the issue...

I made the changes to php.ini shown above and got a new error:

warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in C:\wamp\www\drupal-5.1\includes\common.inc on line 1970.

After searching 'til I was tired and crabby, I cobbled together enough information to do the following:
I opened up common.inc in the includes directory and changed the following section...

return mail(
$to,
mime_header_encode($subject),
str_replace("\r", '', $body),
join("\n", $mimeheaders)

to this...

return mail(
$to,
mime_header_encode($subject),
str_replace("\r\n", '', $body),
join("\n", $mimeheaders)

***look closely at the "str_replace" line or you might miss the change***

and it worked! Well, to be honest, the email that was sent to the new user was barely readable because the text wrapping was all effed up, but I'll work on that and keep you posted.

Cheers,
mj

madhavok’s picture

The solution I offered above worked for some of Drupal's outgoing mail functions, but not all.

Here's the list:

Signup - works
Password Request - works
Group Join Request - doesn't work
Group mass mail - works
Direct Contact - doesn't work
Contact form - says it doesn't work, but it does
Contact form autorespond - doesn't work

After banging around for hours and hours and hours... I got fed up. I took an old Dell box, slapped Ubuntu Linux Server 6.10 on it and installed postfix. Problem solved.

ms2011’s picture

The issue is explained here:

http://cr.yp.to/docs/smtplf.html

@madhavok: The email wasn't readable because you removed all the line-breaks. Instead, you need to convert them from Unix (LF) line-breaks to Windows line-breaks (CRLF). Try this:

    return mail(
      crlf($to),
      crlf(mime_header_encode($subject)),
      crlf($body),
      join("\r\n", $mimeheaders)
    );
  }
}

function crlf($s) {
  return str_replace("\n", "\r\n", str_replace("\r\n", "\n", $s));
}

Hope this helps!

Mike Smullin
http://www.mikesmullin.com/

jurgenhaas’s picture

Thanks mikesmullin, this is working perfectly. Is there a chance that this goes into the core somehow?

ms2011’s picture

On second thought, this is actually the only part that is necessary:

    return mail(
      $to,
      mime_header_encode($subject),
      str_replace("\n", "\r\n", str_replace("\r\n", "\n", $body)), // formatted for Windows (CRLF). See http://pobox.com/~djb/docs/smtplf.html
      join("\r\n", $mimeheaders)
    );

Mike Smullin
http://www.mikesmullin.com/

robbin.zhao’s picture

Here is an video about using email in Drupal, please check!

dhtml’s picture

There is a package i made. However, i made it on windows. It involves some c programming.

The end product is that, mails sent locally are forwarded to my local database. and i have a
custom package that i can use to view my emails on http://localhost/sendmail/

It works similarly to the fake_sendmail stuff except that this one does not require an internet
connection.

It works well with drupal.

prabhatjn’s picture

Acquia desktop solve problem for me, I already had everything installed (apache etc.) I just installed it on top.

P.