29

I need to send email messages from my localhost.

I am using wamp server and my site is loaded on my own server, please could you suggest how to send emails using my localhost and PHP?

Benjol
  • 63,995
  • 54
  • 186
  • 268
Prasoon
  • 1,445
  • 4
  • 13
  • 10
  • You would probably need something like a smtp client configured in the background. Maybe sendmail or something like this... – Eddy Freddy Oct 19 '11 at 11:02
  • read this post http://roshanbh.com.np/2007/12/sending-e-mail-from-localhost-in-php-in-windows-environment.html – Gowri Oct 19 '11 at 11:03
  • possible duplicate of [How to configure WAMP (localhost) to send email using Gmail?](http://stackoverflow.com/questions/600725/how-to-configure-wamp-localhost-to-send-email-using-gmail) – mario Oct 19 '11 at 11:23
  • You will probably need to install a local SMTP Server. See http://stackoverflow.com/questions/4532486/failed-to-connect-to-mailserver-at-localhost-port-25 – Caltor Nov 19 '12 at 12:30

4 Answers4

6

Here's the steps to achieve this:

  • Download the sendmail.zip through this link

    • Now, extract the folder and put it to C:/wamp/. Make sure that these four files are present: sendmail.exe, libeay32.dll, ssleay32.ddl and sendmail.ini.
    • Open sendmail.ini and set the configuration as follows:

    • smtp_server=smtp.gmail.com

    • smtp_port=465
    • smtp_ssl=ssl
    • default_domain=localhost
    • error_logfile=error.log
    • debug_logfile=debug.log
    • auth_username=[your_gmail_account_username]@gmail.com
    • auth_password=[your_gmail_account_password]
    • pop3_server=
    • pop3_username=
    • pop3_password=
    • force_sender=
    • force_recipient=
    • hostname=localhost

    • Access your email account. Click the Gear Tool > Settings > Forwarding and POP/IMAP > IMAP access. Click "Enable IMAP", then save your changes.

    • Run your WAMP Server. Enable ssl_module under Apache Module.

    • Next, enable php_openssl and php_sockets under PHP.

    • Open php.ini and configure it as the codes below. Basically, you just have to set the sendmail_path.

[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP =
; http://php.net/smtp-port
;smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = you@domain.com
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"
  • Restart Wamp Server

I hope this will work for you..

Siraj Khan
  • 2,328
  • 17
  • 18
  • In 2020, Google blocks requests from insecure sources by default, which is probably the case if you attempt to send an email through your local server. To activate this function, you had to activate the access of less secure applications via this link: https://myaccount.google.com/lesssecureapps?pli=1. – cyclone200 Sep 10 '20 at 14:39
2

Open your php.ini and find the [mail function] section

After that you have to change the options that are following and are relevant to your SMTP settings.

Settings to change :

SMTP = ; Enter here the address of your SMTP server
smtp_port = 25

Finaly from with your PHP script you have to use the mail function http://php.net/manual/en/function.mail.php

KodeFor.Me
  • 13,069
  • 27
  • 98
  • 166
0

You can use the mail function in PHP. http://php.net/manual/en/function.mail.php

As you are hosting it yourself, you have to check your internet provider smtp and update php.ini with it and that should work.

dyesdyes
  • 1,147
  • 3
  • 24
  • 39
0

In php.ini, set following parameters:

  • SMTP
  • smtp_port
  • sendmail_from
  • sendmail_path
Riz
  • 9,703
  • 8
  • 38
  • 54