0

I'm making a contact form so that someone can send a message to a specified email. However, I get an error message which is very persistent and won't go away:

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\mail.php on line 10

I tried putting in ini_set() on line 10 as specified, however it doesn't change anything. I tried researching what might be the case, but so far haven't come across anything. I was thinking maybe WAMP doesn't support mail.


HTML Code

<form action = "mail.php" method=  "POST">
    <p>Name</p> <input name = "name" type = "text">
    <p>Email</p> <input name = "email" type = "text">

    <p>Message</p><textarea name = "message" rows = "6" cols = "25"></textarea><br />
    <input value = "Send" type = "submit" >
    <input value = "Reset Form" type = "reset">
</form>

Where a form is successfully made which sends data to mail.php through the submit button.


PHP code

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$recipient = "To: myawesome.email@gmail.com";
$mailheader = "From: $name \r\n";
$formcontent= "From: $email \r\n Message: $message";

mail($recipient, $mailheader, $formcontent) or die("Error!");
echo "Your message has been delivered." . " -" . "<a href='form.html' style='text-decoration: none; color: #ff0099;'> Return Home </a>";
?>

Where mail.php is supposed to take $recipient, $mailheader, and $formcontent and email them to the specified address.

Any help is much appreciated.

Time
  • 3
  • 2
  • 4
  • is your mail settings setup properly? – Jhonathan H. Apr 11 '13 at 01:10
  • Possibly related/duplicate: http://stackoverflow.com/questions/1993070/sending-emails-with-wamp – lc. Apr 11 '13 at 01:23
  • Doesn't seem like it. Even my other basic things such as REQUEST are coming up empty (without any syntax errors). As of right now I'm guessing it's very likely that my php.ini has some problems in it. – Time Apr 16 '13 at 04:02

2 Answers2

3

Either you do not have a mail server running on port 25 (most likely the case), or you have a software firewall blocking the port.


Note that even with a locally running mail server, your ISP will most likely block port 25 - a normal practice to prevent spam.

To test from a local server, and have emails actually get delivered, you will most likely need use an external email provider - and connect to it on a port other than 25. Gmail's SMTP server (TLS, port 465) will work wonders here, but you will need to authenticate and send from a Gmail account.

lc.
  • 113,939
  • 20
  • 158
  • 187
0

Did u try to check if your mail server is properly config or config it like this sample

// Please specify your Mail Server - Example: mail.example.com.

ini_set("SMTP","mail.example.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.

ini_set("smtp_port","25");

// Please specify the return address to use

ini_set('sendmail_from', 'example@YourDomain.com')
;

or check you php.ini file for this. heres a sample config.

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

; For Win32 only.
;sendmail_from = me@example.com
; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
Jhonathan H.
  • 2,734
  • 1
  • 19
  • 28