103

Is there a way that I can configure the WAMP server for PHP to enable the mail() function?

Sahan Serasinghe
  • 1,591
  • 20
  • 33
user544079
  • 16,109
  • 42
  • 115
  • 171
  • different ways here: https://stackoverflow.com/questions/16830673/wamp-xamp-send-mail-using-smtp-localhost – T.Todua Nov 23 '19 at 11:07

8 Answers8

212

Configuring a working email client from localhost is quite a chore, I have spent hours of frustration attempting it. I'm sure someone more experienced may be able to help, or they may perhaps agree with me.

If you just want to test, here is a great tool for testing mail locally, that requires almost no configuration:

http://www.toolheap.com/test-mail-server-tool/

starball
  • 20,030
  • 7
  • 43
  • 238
Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
  • 16
    Works with wamp with no config watsoever. Just open the .eml with windows live mail (no config needed). – Benjamin Crouzier Jan 28 '13 at 10:36
  • Working on Win7, working with WAMP just after install – Muhammad Ahsan Jun 09 '14 at 07:03
  • 5
    If (like me) you came to this great solution after tweaking php.ini, remember the default config: [mail function] SMTP = localhost smtp_port = 25 – BenL Dec 12 '14 at 11:01
  • My php.ini file is set up correctly, but I get no e-mails in the specified folder after setting up this tool on win 8.1. What am I doing wrong!? – not_a_generic_user Dec 20 '14 at 09:38
  • This is a great solution, but I'm having trouble with performance. It seems the more content a mail contains, the slower it will be to get to me. Does anyone have a solution, could it just be my aging computer? – Vael Victus Jan 20 '15 at 16:39
  • 1
    Works on windows 8.1 too, installed this for testing mails using wamp server – Vamsi Tallapudi Mar 11 '15 at 15:20
  • Wow useful, installed with no configuration in 2 minutes, refreshed my page, and boom the error message disappeared and received the email on my desktop. – Andrew Oct 11 '15 at 18:17
  • This is a wonderful tool and it helps dev a lot. We have found a problem with it in that it does NOT handle the case where "." is present in column zero of a logical record sent to SMTP. Zend formats our email and it correctly adds a "dot" to the string when the logical start of the line (every 75th character I think) is already a "dot". It is even commented in the zend protocol code. What this means is that if the character at logical pos 0 of each line is a "dot" then the test server tool does not properly handle it and the "extra dot" appears in the email received by the end user. – bill Apr 05 '16 at 15:57
  • 2
    Worked brilliantly for me using WAMP 4 on Win10. Thanks Wesley! – nickstaw Feb 07 '17 at 14:19
  • 1
    How did you download it? I only see google ads in the download section. – qwertzman Jan 14 '19 at 09:40
  • 5
    to whoever doesn't find the download link go to here: https://toolheap.com/test-mail-server-tool/users-manual.html – Desolator Feb 10 '19 at 19:28
  • This is what I call a good piece of software. 10 years later and it still works without any configuration needed at all, on Win 10. – Varin Feb 25 '19 at 17:10
  • Wish I knew about this years ago lol. Still works with Wamp, Win 10. – Second2None Mar 31 '19 at 12:22
  • 3
    For those who want to download this without disabling adblock, here is the download link: https://toolheap.com/test-mail-server-tool/TestMailServerToolSetup.exe – Donald Duck Aug 28 '19 at 15:52
  • @BenL localhost didn't work as smtp for me. I had to use the ip address 127.0.0.1 – I Want Answers Mar 15 '20 at 11:28
45

Install Fake Sendmail (download sendmail.zip). Then configure C:\wamp\sendmail\sendmail.ini:

smtp_server=smtp.example.com
smtp_port=465
auth_username=user@example.com
auth_password=your_password

The above will work against a email account. And then configure php.ini:

sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"

Now, restart Apache, and that is basically all you need to do.

Vit Bernatik
  • 3,566
  • 2
  • 34
  • 40
gianjey
  • 451
  • 4
  • 2
  • 3
    +1 for turnkey solution. As an added resource for those who need a little more detail on the steps: http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/ – Prusprus Feb 17 '14 at 00:27
  • @gianjey Will this work with other accounts such as Hotmail or do you need a Gmail account registered to use this? – Ryman Holmes Apr 06 '14 at 13:18
  • 1
    dang this method doesn't appear to be working anymore ... assuming i've gotten everything set up correctly – Banning Nov 05 '14 at 04:32
  • Hi @Banning, I was able to set this up without difficulty just now so it still works. Make sure you don't have two-step authentication configured on the GMail account. Anyway, this was a good guide - http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/ – faludi Nov 25 '14 at 16:00
  • I got message of successful email but mail not received in my inbox. any help? – Wasim A. Dec 27 '14 at 18:25
  • I'm getting this message in Gmail: "Someone just tried to sign in to your Google Account *******@gmail.com from an app that doesn't meet modern security standards.: – Flion Jan 07 '16 at 22:30
  • 1
    Cant believe this worked first try!!! so incredible. Only part that messed me up is, if you are using gmail you need to put in your gmail user name and password so it can sign into the email client to SEND the email. NOTE: if you are going to do this, make a new gmail account since this increases the risk of security risk. – William Howley Sep 29 '16 at 14:18
  • @DarkBee ok as you wish, But are you sure this answer is still relevant? It seems that it doesn't work anymore with google... Why to keep answer that is not working anymore? – Vit Bernatik Aug 30 '23 at 13:10
  • 1
    That isn't relevant, you could still configure another SMTP server with this method, also there already numerous questions (and answers) on how to use google's SMTP server on SO, like [this one](https://stackoverflow.com/questions/72113637/how-to-use-phpmailer-after-30-may-2022-when-less-secure-app-is-no-longer-an-o) – DarkBee Aug 30 '23 at 13:12
  • @DarkBee yes that is correct. But could you maybe then update at least "smtp.GOOGLE.com"? Cos it is suggestive and I think not working... – Vit Bernatik Aug 30 '23 at 13:14
5

Using an open source program call Send Mail, you can send via wamp rather easily actually. I'm still setting it up, but here's a great tutorial by jo jordan. Takes less than 2 mins to setup.

Just tried it and it worked like a charm! Once I uncommented the error log and found out that it was stalling on the pop3 authentication, I just removed that and it sent nicely. Best of luck!

David Hobs
  • 4,351
  • 2
  • 21
  • 22
  • If you're using a Gmail account, you need to allow access for less secure apps. To do this, when you've done what is says in the tutorial linked in this answer and opened a PHP page with `mail`, you will receive an email from Google saying that a sign-in attempt was blocked. In that email, click on "Check activity", and in the page that opens, click on "Yes, it was me", then click on "Learn more", then click on "If 'Less secure app access' is off for your account", then click on "turn it back on", and then turn the switch on. – Donald Duck Aug 28 '19 at 16:21
  • Also, you must specify a `from` header when calling `mail` in PHP. For example, you can do `mail("to@example.com", "Subject", "Content", "From: youremailaddress@gmail.com")` (it's the last parameter that's important). – Donald Duck Aug 28 '19 at 16:28
2

I tried Test Mail Server Tool and while it worked great, you still need to open the email on some client.

I found Papercut:

https://github.com/ChangemakerStudios/Papercut-SMTP (updated URL for 2021)

For configuration it's easy as Test Mail Server Tool (pratically zero-conf), and it also serves as an email client, with views for the Message (great for HTML emails), Headers, Body (to inspect the HTML) and Raw (full unparsed email).

It also has a Sections view, to split up the different media types found in the email.

It has a super clean and friendly UI, a good log viewer and gives you notifications when you receive an email.

I find it perfect, so I just wanted to give my 2c and maybe help someone.

Fábio Duque Silva
  • 2,146
  • 1
  • 18
  • 16
2

You need a SMTP server to send your mail. If you have one available which does not require SMTP authentification (maybe your ISP's?) just edit the 'SMTP' ([mail function]) setting in your php.ini file.

If this is no option because your SMTP server requires authentification you won't be able to use the internal mail() function and have to use some 3rd party class which supports smtp auth. e.g. http://pear.php.net/package/Mail/

mwallisch
  • 1,751
  • 2
  • 21
  • 29
1

Sendmail wasn't working for me so I used msmtp 1.6.2 w32 and most just followed the instructions at DeveloperSide. Here is a quick rundown of the setup for posterity:

Enabled IMAP access under your Gmail account (the one msmtp is sending emails from)

Enable access for less secure apps. Log into your google account and go here

Edit php.ini, find and change each setting below to reflect the following:

; These are commented out by prefixing a semicolon
;SMTP = localhost
;smtp_port = 25

; Set these paths to where you put your msmtp files.
; I used backslashes in php.ini and it works fine.
; The example in the devside guide uses forwardslashes. 
sendmail_path = "C:\wamp64\msmtp\msmtp.exe -d -C C:\wamp64\msmtp\msmtprc.ini -t --read-envelope-from"

mail.log = "C:\wamp64\msmtp\maillog.txt"

Create and edit the file msmtprc.ini in the same directory as your msmtp.exe file as follows, replacing it with your own email and password:

# Default values for all accounts
defaults
tls_certcheck off
# I used forward slashes here and it works.
logfile C:/wamp64/msmtp/msmtplog.txt

account Gmail
host smtp.gmail.com
port 587
auth on
tls on
from ReplaceWithYourEmail@gmail.com
user ReplaceWithYourEmail@gmail.com
password ReplaceWithYourPassword
account default : gmail
iyrin
  • 612
  • 5
  • 14
1

Instead of installing and configure own SMTP server it is possible (easier) to use one's personal Gmail email and configure PHP/WAMP to use it and send email through it.

As of 2023 gmail does not support for personal users SMTP by default. So some earlier answers seems to be outdated. Now it seems to be necessary to enable 2-Way Authentication first and then generated App Password.

So let's configure Google side first:

  1. In your Gmail click your icon (in top right)->Manage your Google Account->Security->2-Step Verification
  2. set it up (you will need to receive SMS).
  3. Then when it is set up go to 2-Step Verification again
  4. At bottom there is App password->click it
    • then Select app as "mail"
    • Select device as "Windows computer"
    • click "generate"
  5. You will get 16 letters password which you will use later. So copy it.

Then you download Sendmail with TLS support. Basically it is app that takes text file with email address and subject and body. Then connects to SMTP server and send that.

You can download it from git hub:

https://github.com/sendmail-tls1-2/main

I used this file to be precise: Sendmail_v33_TLS1_2.zip

Unzip and configure sendmail.ini like following (don't forget to change auth_username and auth_password to your email and password):

smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=tls
error_logfile=error.log
; note this is useful to uncoment and peek if something doesnt work
; debug_logfile=debug.log
auth_username=yourEmail@gmail.com
auth_password= that-16-letters-password-you-got-from-Google-App-Password

To test sendmail is working create test.txt in sendmail folder. Like this (but edit your receive email address):

From: anything@example.com 
To: FillYourReceive@email.com 
Subject: Your Subject 
Your Body message
Your Body message second line

Then go to command line to sendmail folder and run it as:

sendmail.exe < test.txt

You shall receive email in few seconds. If not check error.log file or enable debug file in sednmail.ini and check debug.log file also.

When this works configure your php.ini (wamp icon->PHP->php.ini [apache module]

;SMTP = localhost
;smtp_port = 25
sendmail_from ="admin@wampserver.vbe"
sendmail_path = "c:/wamp64/bin/Sendmail_v33_TLS1_2/sendmail.exe -t"
;mail.force_extra_parameters =
mail.add_x_header = Off

Of course edit sendmail_path to where you have sendmail.exe and best copy it to WAMP folder.

Restart apache wamp icon->Apache->Service Administration 'wampapache64'->Restart Service

Then create web page in your document root like test_mail.php with following data. (Just remember to change FillYOurReceiveEmail :

<?php
echo "<br>sendmail_path:".strval(ini_get('sendmail_path'));

$from = "anything@anywhere.com";
$to = "FillYOurReceiveEmail@gmail.com";
$subject = "Your email subject";
$message = "Your email body message";
$headers = [ "From: $from" ];

$ret = mail( $to, $subject, $message, implode( '\r\n', $headers ) );
// OR - PHP 7.2.0 or greater
//mail( $to, $subject, $message, $headers );
echo "<br>ret :".strval($ret);
?>

Then open in your browser page localhost/test_mail.php

You shall see something like:

sendmail_path:c:/wamp64/bin/Sendmail_v33_TLS1_2/sendmail.exe
ret :1

And you shall receive email to your filled email.

Vit Bernatik
  • 3,566
  • 2
  • 34
  • 40
0

I used Mercury/32 and Pegasus Mail to get the mail() functional. It works great too as a mail server if you want an email address ending with your domain name.