Jump to content

Mail Function Problem


nworst
 Share

Recommended Posts

I've made a mailform, but sending the mail doesn't yet work out as it should. This is the error code I get when sending the email:

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() in C:\xampp\htdocs\Testweb\startpagina.php on line 106

What port should I be using if 25 (default) doesn't work?

Edited by nworst
Link to comment
Share on other sites

Yes, I know what localhost is. I assume the answer to my question is "yes" then. OK, well then if you haven't already done it, you need to install MySQL. Once MySQL is installed and working, you need to edit your php.ini file to use the mysql extension for PHP. If you downloaded the PHP installer, I'm not sure if it even includes the mysql extension. It might include it though.In your php.ini file you'll find a line that defines where the extensions are located. You'll want to check inside that folder and see if you see php_mysql.dll in there. If so, then after you install MySQL all you need to do is edit the php.ini file to use the MySQL extension. There's a section in php.ini called "extensions" where you'll see how to enable the extension. After doing all of that, you'll need to restart the web server to pick up the changes.If you aren't sure where php.ini is, create a page with this in it:<?php phpinfo(); ?>Near the top, it will tell you which configuration file it's using. That's the one you need to edit to make the changes. If it doesn't list anything there, then it can't find php.ini and it's using the default settings for everything. That's a problem.If you don't want to install and configure MySQL yourself, there are several packages that include Apache, PHP, and MySQL bundled together. If you want to install one of those you'll need to uninstall or disable your current web server first.

Edited by justsomeguy
Link to comment
Share on other sites

Hmm.. I don't get Fatal error: ... but now I get this:

  The website cannot display the page  HTTP 500     Most likely causes:•The website is under maintenance.•The website has a programming error.    What you can try: 	 Refresh the page.  	 Go back to the previous page.  	 More information

Thanks anyways.

Link to comment
Share on other sites

Thanks for your tut how to make login :) Would have never found out myself.mmm not solved, now register.php loads, but when I click submit it gives the same error as above :)also same with login.php, when I click log in, it gives the error

Edited by nworst
Link to comment
Share on other sites

Oops, I just assumed you were using Apache.What I meant was, did you download your webserver, PHP, and MySQL all separately and then install them one by one, or did you install one of the complete packages available like WAMP or XAMPP.

Edited by Synook
Link to comment
Share on other sites

HTTP 500 = internal server error, by the way. I would suggest you download a AMP package like justsomeguy suggested. At least then you can be sure you will have the MySQL extension in PHP.

Link to comment
Share on other sites

Downloaded XAMPP, but when I try to register (filled in all the fields in register.php), I get the following:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Testweb\db.php on line 3Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in C:\xampp\htdocs\Testweb\db.php on line 4Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Testweb\register.php on line 27Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\Testweb\register.php on line 27Warning: mysql_query() expects parameter 2 to be resource, boolean given in C:\xampp\htdocs\Testweb\db.php on line 8Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Testweb\register.php on line 28Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Testweb\register.php on line 32Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\Testweb\register.php on line 32Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Testweb\register.php on line 33Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\Testweb\register.php on line 33Warning: mysql_query() expects parameter 2 to be resource, boolean given in C:\xampp\htdocs\Testweb\db.php on line 8Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Testweb\db.php:3) in C:\xampp\htdocs\Testweb\register.php on line 37

Also, above the register.php page and login.php page it says the following:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Testweb\db.php on line 3Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in C:\xampp\htdocs\Testweb\db.php on line 4

Link to comment
Share on other sites

Ok, username now is root, and now the errors above the register.php and login.php page are gone. But when I now try to register, I get the following:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Testweb\register.php on line 28Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\Testweb\register.php:28) in C:\xampp\htdocs\Testweb\register.php on line 37

If you need any scripts, I'll post them

Link to comment
Share on other sites

This is the code of register.php:

<?phprequire_once 'db.php';$page_mode = isset($_POST['page_mode']) ? $_POST['page_mode'] : '';$error_string = '';if ($page_mode == 'register'){  $email = trim($_POST['email']); // trim to remove whitespace  $name = trim($_POST['name']); // trim to remove whitespace  $password = $_POST['password'];  $conf_password = $_POST['conf_password'];  if (!isValidEmail($email))	$error_string .= 'Vul aub een geldig emailadres in.<br>';  if ($name == '')	$error_string .= 'Vul uw naam in aub.<br>';  if (strlen(trim($password)) < 6)	$error_string .= 'Het wachtwoord moet uit minstens 6 letters bestaan.<br>';  if ($password != $conf_password)	$error_string .= 'Uw wachtwoord komt niet overeen met het bevestigde wachtwoord.<br>';  if ($error_string == '')  {	$result = db_query("SELECT id FROM users WHERE email='" . mysql_real_escape_string($email) . "'");	if (mysql_num_rows($result) > 0)	  $error_string .= 'Dit emailadres is al geregistreerd.<br>';	else	{	  $email = mysql_real_escape_string($email); // protect against SQL attacks	  $name = mysql_real_escape_string($name);	  $password = sha1($password); // hash password	  	  db_query("INSERT INTO users (email, name, password) VALUES ('{$email}', '{$name}', '{$password}')");	  header('Location: thankyou.php');	  exit();	}  }}function isValidEmail($email = ''){	return preg_match("/^[\d\w\/+!=#|$?%{^&}*`'~-][\d\w\/\.+!=#|$?%{^&}*`'~-]*@[A-Z0-9][A-Z0-9.-]{1,61}[A-Z0-9]\.[A-Z]{2,6}$/ix",$email);}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head> <link rel="stylesheet" type="text/css" href="style.css" /> <title>Registreren</title> <meta name="description"  content="" /> <meta name="keywords"  content="" /> <style type="text/css">	.error_text {color:#FF0000;width:400px;text-align:center;}	.left_box {float:left;width:150px;text-align:right;padding-right:5px;}	.right_box{clear:right;}  </style></head><body><div class="container"><div class="header"><h1 class="header"><br /><br /><br /><br /><div class="menu" style="font-size:12px"><?php include("menu.php"); ?>	</div></h1><br /><br /></div><div class="left"><?php include("left.php"); ?></div><div class="content"> <div class="error_text"><?php echo $error_string; ?></div> <form action="register.php" method="post"> <input type="hidden" name="page_mode" value="register"> <div class="left_box">Emailadres</div> <div class="right_box"><input type="text" name="email" size="30" maxlength="255" value="<?php if (isset($email)) echo $email; ?>"></div>  <div class="left_box">Naam</div> <div class="right_box"><input type="text" name="name" size="30" maxlength="255"></div> <div class="left_box">Wachtwoord</div> <div class="right_box"><input type="password" name="password" size="30"></div>  <div class="left_box">Bevestig wachtwoord</div> <div class="right_box"><input type="password" name="conf_password" size="30"></div> <div class="left_box"> </div> <div class="right_box"><input type="submit" value="Registreer" size="30"></div> </form></div><br /></div><div class="footer"></div></body></html>

Link to comment
Share on other sites

If I type in a password at db.php, it says

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\Testweb\db.php on line 3Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in C:\xampp\htdocs\Testweb\db.php on line 4Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\Testweb\register.php on line 27Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in C:\xampp\htdocs\Testweb\register.php on line 27Warning: mysql_query() expects parameter 2 to be resource, boolean given in C:\xampp\htdocs\Testweb\db.php on line 8Access denied for user 'ODBC'@'localhost' (using password: NO)

and if I don't type a password it says 'No database selected'...Am I just so stupid or is it not my fault? unsure.gif

Link to comment
Share on other sites

This is db.php:

<?php$con = mysql_connect('localhost', 'root', ''); // host, username, passwordmysql_select_db('my_db', $con);function db_query($sql){  return mysql_query($sql, $GLOBALS['con']);}?>

I filled in the name of the database behind mysql_select_db, should it be filled in somewhere else as well?

Edited by nworst
Link to comment
Share on other sites

No, that's the only place it needs it. There should be error checking there also though:$con = mysql_connect('localhost', 'root', '') or exit(mysql_error()); // host, username, passwordmysql_select_db('my_db', $con) or exit(mysql_error());Otherwise, make sure the root user has access to that database.

Edited by justsomeguy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...