0

I have this code here:

for HTML:

<form action="process.php" method="POST"><br />
<b>Send message to all users:</b>
<br />Subject: <input type="text" name="subject">
<br />Message:<br />
<textarea name="message" ></textarea>
<br>
<input type="Submit">
</form>

for PHP:

<?php 

mysql_connect("localhost", "root", "")or die("cannot connect server ");
mysql_select_db("db_cl3")or die("cannot select DB");

$subject = $_POST['subject'];        
$message = $_POST['message'];

$getusers = mysql_query("SELECT * FROM tbl_info");

while($result = mysql_fetch_array($getusers)) { 
$emailaddress = $result['email'];

mail($emailaddress,$subject,$message);

mysql_close();
}
?>

And i get this error:

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\occc\process.php on line 14

can any one tell me how to fix the error?

Thanks in advance.

imNEWBIE
  • 9
  • 1
  • 3
    You shouldn't send E-Mail from your local machine. You need a mail server – Pekka Mar 14 '13 at 20:23
  • 3
    you also shouldnt use `mysql`, but use `mysqli`. and what the hell are u doing connecting to the db as root?!? create a user before u kill all the kittens! – PlantTheIdea Mar 14 '13 at 20:24
  • @LifeInTheGrey Most probably developping on xampp, which is causing the error as well I guess. – user2019515 Mar 14 '13 at 20:28
  • You've already been told, but here's the "*official*" message we usually tell people: [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – h2ooooooo Mar 14 '13 at 20:33

1 Answers1

0

you need to use an smtp server, a server with SMTP Services running on it, a mail server of some sort. There are a few mail servers that allow smtp relay, some require authetnication, some don't, it all depends. You can bounce stuff off of google's smtp server, or if your company has one you can use that one as well. Generally it's smtp.servername.com using port 25, but that's not always the case. IIS used to support SMTP server with Windows Server IIS 7 or less, but I think they've phased it out with IIS 8.

apollosoftware.org
  • 12,161
  • 4
  • 48
  • 69