0

I want to send email using php in html. For the purpose I wrote the following code:

<?php
    if($_SERVER['REQUEST_METHOD'] == 'POST')
    {
        if ( mail ('ahmsjahan@gmail.com','New Website message' ,$_POST['message']))
             $status = "Thank you for your message";    
    }
    if ( isset($status))
        echo $status;
 ?>
  <html>
    <head>
        <title>
            I am don
        </title>
    </head>

    <body>
        <h1>
            Contact Form
        </h1>

        <form action = "" method = "post">
            <ul>
                <li>
                    <label for = "name"> Name: </label>
                    <input type = "text" id="name"name = "name">
                </li>

                <li>
                    <label for = "email" > Email: </label>
                    <input type="email" id="email" name = "email">
                </li>
                <li>
                    <label for = "messsage" > Message: </label><br>
                    <textarea name = "message" id="message"></textarea>
                </li>
                <li>
                    <input type = "submit" value= "submit">
                </li>
            </ul>
        </form>
    </body>
</html>

I am getting error like this:

While sending ( ! ) Warning: 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\form.php on line 4

Should I change something at line 4 in php.ini file?

jahan
  • 521
  • 1
  • 4
  • 15
  • 1
    Unless you're running a mail server on your localhost, you'll need to configure PHP to point at your SMTP server. I wouldn't bother with this though. Use something like Swiftmailer so you can easily handle SMTP over SSL and authentication. – Brad Apr 23 '14 at 18:57
  • you'll need to configure PHP to point at your SMTP server. – jahan Apr 23 '14 at 18:59
  • 1
    Check this (http://stackoverflow.com/questions/16830673/wamp-send-mail-using-smtp-localhost) – Wit Wikky Apr 23 '14 at 19:01

1 Answers1

0

Open your php.ini file and Search for [mail function] and add/change the details of your mail server.Restart your web server.

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

; For Win32 only.
;sendmail_from = me@example.com
Parimal
  • 183
  • 1
  • 11