Web Site Creator Web Hosting Help
   PHP Sample Files


PHP code samples, such as connecting to an Access database, are now available. Log into your Web Hosting control panel and go to the Help section to create Sample Files in your Web Hosting account. A folder named "samplefiles" will be created in the root directory containing the samples, with the necessary account information already filled in. Any time a new code sample is released it will be added to this folder in your account.

For your convenience, some of the code samples are included below.

Sample Files

Database Sample
Including Files
PHPMailer - sending Mail using php
How to use Curl
How to make a phpinfo file

Database Sample

Here are three sample ways to connect to a database.  We recomend placing one of the below methods into an include file - a file that contains nothing but the info below and any other database access information so you only have to configure it once, regardless of how many times you use it, or how many pages use it.

Replace the username, password, and database with the information that relates to your specific database before using.

How to access SQL Server from PHP with out a DSN
If you have a SQL Server account with us, it is very easy to access your database from PHP. Here is sample code for establishing a connection to the database:

$server = "database1.ehost-services.com,1433";
$dbusername = "USERNAME"; //database username
$dbpassword = "PASSWORD"; //database password
$dbdatabase = "DATABASE"; //database name $sqlconnect = @mssql_connect($server, $dbusername, $dbpassword) or die("Couldn't connect to SQL Server on $server");
$sqldb = @mssql_select_db($dbdatabase,$sqlconnect) or die("Couldn't open database $dbdatabase");

How to access SQL Server from PHP WITH a DSN
Every one of our web sites can utilize an MS Access database. You must create the database and upload it to your /Db directory. This is very important- it will not function correctly from any other directory. The /Db directory has special write access that lets you update your database. Here is sample code for establishing a connection to the database:

$dsn="UserDBConn"; //Replace this with the name of the DSN
$dbusername="USERNAME"; //database username
$dbpassword="PASSWORD"; //database password
$dbdatabase="DATABASE"; //database name

$sqlconnect = @odbc_connect($dsn, $dbusername, $dbpassword) or die("Couldn't connect to SQL Server using DSN $dsn");
$sqldb = @mssql_select_db($dbdatabase,$sqlconnect) or die("Couldn't open database $dbdatabase");

How to access MySQL Server from PHP
$server="mysqldb1.ehost-services.com";//database location
$dbusername="USERNAME"; //database username
$dbpassword="PASSWORD"; //database password
$dbdatabase="DATABASE"; //database name

$dbc = @mysql_connect ($server, $dbusername, $dbpassword) or die('Counld not connect to Mysql Server:' . mysql_error());
mysql_select_db ($dbdatabase) or die('Could not connect to the database:' . mysql_error());

Back to top


Including Files
<html>
<body>

<?php

//Include a file in the same directory
include("file.php");

//Include a file in a sub directory
include("/folder/file.php");

//Include a file in a directory above the current directory
include("../folder/file.php");

?>
</body>
</html>

Back to top


PHPMailer - sending Mail using php
To send email from your PHP pages, use the following code. The first section is an example of how to send mail from your php page using one of your Web Hosting accounts emails.  In order for this to work properly, you will need to download the "PHPMailer Class" files from SourceForge.  Edit the first section of the file as indicated below:

<?php

$YourEmailAddress ='email@email.com' ; //Email address you want the mail to go to
$Yourname = 'My name'; //Who the email is sent from - this is a name not an email
$MailUsername = 'email@email.com'; //Email address you are using to send the email
$MailPassword = 'EmailPassword; //This is the password of the emali account used to send the emali
$MailServer = 'mailserver.name-services.com'; //Assigned mail server
$MailType = "HTML"; // Can use HTML or TEXT -case doesnt matter

require("class.phpmail.php");  //Change this to the real path of the file - this assumes that the mail script 
                                             //and the included filed are in the same directory


#----------------------- DO NOT EDIT BELOW THIS LINE ------------------------------#

# These are the form Vars - do not edit
$action = $_POST['action'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$comments = $_POST['comments'];

if(strtolower($MailType) == 'html'){
$mailtypetosend = true;
} else {
$mailtypetosend = false;
}

$mail = new PHPMailer();

$mail->From = $email;
$mail->FromName = $email;
$mail->Host = $MailServer;
$mail->Mailer = "smtp";

$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = $MailUsername; // SMTP username
$mail->Password = $MailPassword; // SMTP password

$mail->AddAddress($YourEmailAddress, $Yourname);
$mail->AddReplyTo($ReplyToEmailAddress, $ReplyToEmailname);

$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML($mailtypetosend); // True for HTML, FALSE for plain text
$mail->SetLanguage("en", "include/language/");

//Start the page action upon submittal
if ($action == "contact" ) {
if (empty($_POST['name'])) {
$name = FALSE;
$message .= '<br>Please enter your name</br>';
} else {
$name = $_POST['name'];
}
if (empty($_POST['phone'])) {
$phone = FALSE;
$message .= '<br>Please enter a phone number to reach you at</br>';
} else {
$phone = $_POST['phone'];
}
if (empty($_POST['email'])) {
$email = FALSE;
$message .= '<br>Please enter your email address</br>';
} else {
$email = $_POST['email'];
}
if (empty($_POST['comments'])) {
$comments = FALSE;
$message .= '<br>You did not enter in a message</br>';
} else {
$comments = $_POST['comments'];
}

if($comments && $email && $phone && $name){

$mail->Subject = "Contact Us form from submitted";
$mail->Body = "A contact us form has been submitted from the website\nHere are the details:\n\n\n";
$mail->Body .= "Name: $name \n";
$mail->Body .= "Phone number: $phone\n";
$mail->Body .= "Email Address: $email\n";
$mail->Body .= "Message: $comments\n\n\n";

if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
} else {
$sent = 1;
}


echo "<table width=\"622\" border=\"0\" align=\"left\" class=\"table01\">
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"left\">Thank you for contacting us, We will respond to all inquiries in the order as they are recieved, as soon as it is possible.</span></td>
</tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"left\">Name: $name</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"left\">Email Address: $email</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"left\">Phone Number: $phone</span></td>
</tr>
<tr>
<tr>
<td width=\"526\" class=\"OutlineOne\" align=\"left\">Message: $comments</span></td>
</tr>
<tr>
</table>";
}
}
if(isset($message)) {echo "<left><u><b>$message</span></b></u></left><br>";}

if($sent != 1){
echo "
<table width=\"424\" border=\"0\" align=\"left\" >
<form name=\"form1\" method=\"post\" action=\"contactme.php\">
<input type=\"hidden\" name=\"action\" value=\"contact\">
<tr>
<td colspan=\"2\">Contact Form</td>
</tr>
<tr>
<td>Name</td>
<td>
<input name=\"name\" type=\"text\" value=\"$name\">
</td>
</tr>
<tr>
<td>Email Address </td>
<td><input name=\"email\" type=\"text\" value=\"$email\"></td>
</tr>
<tr>
<td>Phone Number </td>
<td><input name=\"phone\" type=\"text\" value=\"$phone\"></td>
</tr>
<tr>
<td height=\"86\">Message / Comments </td>
<td><textarea name=\"comments\" cols=\"30\" rows=\"5\" value=\"$comments\"></textarea>
</td>
</tr>
<tr>
<td height=\"20\" colspan=\"2\"><left><input type=\"submit\" name=\"Submit\" value=\"Submit\"></left></td>
</tr>
</form>
</table>";
}

?>

Back to top


How to use CURL
<?php

//How to connect using cURL

$ch = curl_init("FULL URL OF SERVER TO POST THE STRING TO"); // URL of gateway for cURL to post to
curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($ch, CURLOPT_POSTFIELDS, $VAR; // use HTTP POST to send form data

### VAR as listed above is the variable that contains the info that is to be sent to the remote host

$resp = curl_exec($ch); //execute post and set the results as the $resp variable
curl_close ($ch);
echo $resp; //this will echo the complete response from the remote host, and you can parse as you see fit

?>

Back to top


How to make a PHP Info page

create a page called anything you like containing only the line:

<?php phpinfo(); ?>

Then upload it to your Web Hosting account and browse to it.

Back to top



Sign Up Now! Overview

Questions? Call sales at
1 (425) 274-4500
Or try our
Visit our Help Center where you can get simple and quick product support.
   is an affiliate of   , a leading domain name services company.
Copyright © 1998-2018 Enom LLC. All rights reserved. Terms & Conditions | Privacy Policy | Abuse Policy