0

I am currently creating a contact form and with the help of thw world wide web I made a php background, which I also understand.

Unfortunately it looks al great to me, but I do get aan error, saying:

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\jquery\mail.php on line 16 [line 16 is the place where the if statement with the mail and the attributes appaeat, see below]

I have honestly no clue what the error means, and my code is below, does anybody now what it means and how I could fix it? Thanks in advance!

<?php
 $name = $_POST['name'];
 $email = $_POST['email'];
 $city = $_POST['city'];
 $message = $_POST['message'];
 $from = 'From: timohoogie'; 
 $to = 'ownemail@gmail.com'; 
 $subject = 'Contact zoeken met whoduniit';
 $human = $_POST['human'];

 $body = "From: $name\n E-Mail: $email\n City: $city\n Message:\n $message";

 if ($_POST['submit'] && $human == '4') {                
     if (mail ($to, $subject, $body, $from)) { 
    echo '<p>Your message has been sent!</p>';
    } else { 
    echo '<p>Something went wrong, go back and try again!</p>'; 
} 
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}

?>

<form method="post" action="mail.php">
            <label for="Name">Naam:</label>
            <input type="text" name="name" id="name" />

            <label for="City">Stad:</label>
            <input type="text" name="city" id="city" />




            <label for="email">Email:</label>
            <input type="text" name="email" id="email" />

            <label for="gevonden"> Hoe heeft u ons gevonden</label>
            <input type="text" name="gevonden" id="gevonden" />

                <br>
                <br>

            <label for="Message">Bericht:</label><br />
            <textarea name="message" rows="20" cols="20" id="message"></textarea>

            <label>*What is 2+2? (Anti-spam)</label>
            <input name="human" placeholder="Type Here">

            <input type="submit" name="submit" value="Submit" class="submit-button" />
        </form>
TimothyUtrech
  • 77
  • 1
  • 6
  • This might help http://stackoverflow.com/questions/16830673/wamp-send-mail-using-smtp-localhost – djthoms Aug 05 '14 at 20:58

2 Answers2

0

mail is a PHP function, yes. But it must be installed on the server that is doing the actual sending. SMTP is a slightly different protocol that seems to be getting triggered because the simple mail function is failing (for it not being installed.)

You need to check with your service provider to see what mail function you should be using.

durbnpoisn
  • 4,666
  • 2
  • 16
  • 30
  • Thanks; for the quick answer! I am gonna try it out tomorrow (its quite late were I leave), but it sounds like a very good suggestin, I will let you know if it works, but anyhow, thanks! – TimothyUtrech Aug 05 '14 at 21:08
0

You need to have a SMTP server running on the machine that hosts this code with your current settings. Or else you need to change the SMTP settings in your php.ini file.

Read more about how to set this up here: http://www.quackit.com/php/tutorial/php_mail_configuration.cfm

If you want to set up your own SMTP server, I dont have any good tips on top of my head, but there are several free server softwares out there. Although, you would probably be better off using a public one, or even you ISP SMTP server.