Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25


I've been trying to set up a forgot password facility on a website which I am building but each time I try to load the page I am greeted by the error:


Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()


How do I go about resolving this?

here is the code I have so far:

<?php if (array_key_exists('forgot',$_POST)) { $email = $_POST['email']; mysql_select_db($database_speedycms, $speedycms); $query_email = "SELECT * FROM tbl_users WHERE email='$email'"; $email = mysql_query($query_email, $speedycms) or die(mysql_error()); $row_email = mysql_fetch_assoc($email); $totalRows_user = mysql_num_rows($email); mysql_query("SELECT * FROM users WHERE email='$email'"); if($totalRows_user == 0) { echo "<span class='form2'>We're sorry, but we could not find a user with that email address.

Please try again.

<a href='forgotpassword.php' class='form'>Return</a></span>"; } else { // create a random password function createRandomPassword() { $chars = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i <= 7) { $num = rand() % 33; $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $password = createRandomPassword(); // generate email $username = $row_email['username']; $msg = "Your new login information is:\n\n"; $msg .= "Username: $username\n"; $msg .= "Password: $password\n"; mail("$email", "Speedy CMS Login Information", "$msg", "From:noreply@domain.com"); // display message echo "<span class='form2'>Thanks. Your new password has been sent to <i>".$row_email['email']."</i>.

<a href='index.php' class='form'>Return</a></span>"; } exit; } ?>


Looks like your server doesn't have a smtp mailserver running. You could use these functions to set a different smtp server:

ini_set('SMTP', "server.com"); ini_set('smtp_port', "25"); ini_set('sendmail_from', "email@domain.com");

Of course you must know an active smtp server.

Good luck!


You have to configure these values on php.ini file

SMTP = smtp.yourdomain.com smtp_port = 25 username = info@yourdomain.com password = yourmailpassord sendmail_from = info@yourdomain.com

You can provide same details as in outlook config. Some servers are checking "sendmail_from" adress also.


It looks like you do not have a SMTP server running on the system your website is running. What kind a server is it?


Looks like you are using a local PHP installation (using WAMPSERVER, EasyPHP or else) because "real" hosts rarely misconfig their server. If it's the case, edit the php.ini and use your ISP settings example:

[mail function] SMTP = mail.yourdomain.com smtp_port = 25


Warning: mail(): SMTP server response: 550 Access denied - Invalid HELO name (See RFC2821 in C:\AppServ\www\VOGUE\email.php on line 38 after add following codes...............

ini_set('SMTP', "server.com");

ini_set('smtp_port', "25");

ini_set('sendmail_from', "email@domain.com");

how to add password of "sendmail_from" account???????


  • Why the controls not update, when call method from other form
  • show message when no rows selected mysql php
  • Run a function from another form vb.net
  • Child form in a mdi parent in C#
  • Number of entries in DB PHP
  • C# Custom Event Handler
  • Offset from end / reverse offset?
  • Using a join with three tables when a field might be null
  • Insert records into two table at once
  • Getting syntax error in mysql-php. You have an error in your SQL syntax;
  • Angular - routerLinkActive and queryParams handling
  • Is it possible to get the word under the mouse cursor in a ``?
  • Randomizing -and remembering that randomisation- multiple choice questions in php
  • Stop Bash Script if Hive Fails
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • Insert into database using onclick function
  • Using $this when not in object context
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Cassandra Data Model
  • Display Images one by one with next and previous functionality
  • Upload files with Ajax and Jquery
  • Web-crawler for facebook in python
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Java static initializers and reflection
  • Authorize attributes not working in MVC 4
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • unknown Exception android
  • Is there any way to bind data to data.frame by some index?
  • Busy indicator not showing up in wpf window [duplicate]
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How can i traverse a binary tree from right to left in java?
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • Conditional In-Line CSS for IE and Others?
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF