PHP mail function not working on localhost.

    By enRaiser

    I made the changes in PHP.ini
    SMTP = ssl://
    smtp_port = 465
    but, after this also mail function was not working.
    I simply wanted some email to be send from my localhost test server,and I dont want to install XAMP, or any other mail server on my local host.I was ok with using GMAIL account.
    So I learned that this I can not use mail(…) function as in  php.ini you can not set SMTP authentication  (username passwd).

    Later I tried PEAR Mail package as suggested in this link,
    but still it was not working.

    After a long trial and error I realized that  I need to un-comment,
    and my problem is solved ,
    Hope this helps you.

    I only tested this on OSX , but it should work with any localhost setting.

    ---------------------ignore following texts-----------

    There are few other work arounds:

    • Install local mail server if you have sufficient rights
    • Change your PHP settings to use other mail server (other open mailserver or auth-based ones like Gmail, Yahoo etc)
    • Use one of available mail libraries which supports IMAP / POP3 to handle mail sending. SwiftMailer or Pear Mail are one of most commonly used.

    You can also use 

    PHPMailer for helping to send email from localhost. Not only the text email, you can send HTML email from localhost in PHP using PHPMailer. Download the PHPMailer from GitHub, also you can get it from our downloadable package.

    To using Gmail SMTP server, you should need to change account access for less secure apps. Don’t worry! Just follow the below steps.

    Nice post.. This is very helpful to learn about mail() function. Thanks once again.

    If you are working with the phpmail function and got the "Mail has been sent" message, it should have been sent from the server. You will now need to check the server logs and see if the message was indeed sent and if it was received properly by the other server.



    PHP must be configured correctly in the php.ini file with the details of how your system sends email. Open php.ini file available in /etc/ directory and find the section headed [mail function].

    Windows users should ensure that two directives are supplied. The first is called SMTP that defines your email server address. The second is called sendmail_from which defines your own email address.

    The configuration for Windows should look something like this:

    [mail function]
    ; For Win32 only.
    SMTP =
    ; For win32 only
    sendmail_from = [email protected]

    Linux users simply need to let PHP know the location of their sendmail application. The path and any desired switches should be specified to the sendmail_path directive.

    The configuration for Linux should look something like this:

    [mail function]
    ; For Win32 only.
    SMTP = 
    ; For win32 only
    sendmail_from = 
    ; For Unix only
    sendmail_path = /usr/sbin/sendmail -t -i


    make the required modification in the php.ini file and try once again.