Skip to main content

Posts

Showing posts from April, 2011

The PHP mail() Function

Syntax
mail(to,subject,message,headers,parameters)


Sample code
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

PHP MySQL Connect to a Database

Before you can access data in a database, you must create a connection to the database. In PHP, this is done with the mysql_connect() function. Syntax

mysql_connect(servername,username,password);
?> Closing a Connection
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// some code

mysql_close($con);
?>