Send Form Contents to E-Mail

I took the time to do this post because I see a lot of students looking everywhere for a PHP E-Mail script, so here it is:

//Created byξGilbertoξCortez http://www.gilbertocortez.com

//Variables

$form = ???Contact Us???;//Form Name

//Inputs From Form

$name = $_POST[‘name’];

$email = $_POST[’email’];

$phone = $_POST[‘phone’];

$city = $_POST[‘city’];

$comments = $_POST[‘comments’];

//E-Mail Headers

$headers = ???From:???.$email. ???\r\n???;//From E-Mail Header

$headers .= ???Cc:ξdebugg@email.com??? . ???\r\n???;//Debugging E-Mail

$to = ???your@email.com???;//To Address

$subject = ???Message From ???.$form.??? Form???;//Subject Line

//Actual E-Mail Message

$message = ???You received a message from the form named: \???”.$form.???\???:

From: ???.$name.???

E-Mail: ???.$email.???

Phone #: ???.$phone.???

City: ???.$city.???

Comments: ???.$comments.???

???;

//Send E-Mail

mail($to,$subject,$message,$headers);

//Page Re-Direct

header (???Location: thankyou.html???);

Hope you like the script, I added notes to it for easier understanding. Just customize the variables up on top from the fields of your form and for your information. Also remember to add or remove them on the message itself if you change the number or name of the variables.

Any questions or comments are appreciated.

Display your last Tweet from Twitter.com

Are you a big Twitter user, and would like to integrate your account into your site? Here is the code to display your last Tweet using the .xml file that is provided by Twitter.

There is only one thing that needs to be changed out. which is the XML file address, you need to input your Twitter ID #. You can get this from clicking on the RSS feed at the bottom of your Twitter Main Page, and extracting this from the URL.

<?php
//Put XML Contents Into Array (PHP.net Function)
function xml2assoc($xml) {
$tree = null;
while($xml->read())
switch ($xml->nodeType) {
case XMLReader::END_ELEMENT: return $tree;
case XMLReader::ELEMENT:
$node = array(‘tag’ => $xml->name, ‘value’ => $xml->isEmptyElement ? ” : xml2assoc($xml));
if($xml->hasAttributes)
while($xml->moveToNextAttribute())
$node[‘attributes’][$xml->name] = $xml->value;
$tree[] = $node;
break;
case XMLReader::TEXT:
case XMLReader::CDATA:
$tree .= $xml->value;
}
return $tree;
}
//Open XML Reading Object
$xml = new XMLReader();
//Open XML File (Replace {id} with your Twitter ID)
$xml->open(‘http://twitter.com/statuses/user_timeline/{id}.xml’);
//Put Document in Arrays
$assoc = xml2assoc($xml);
//Close XML Object
$xml->close();
//Store Result
$lastTweet = $assoc[0][‘value’][0][‘value’][2][‘value’];
//Print Result
echo $lastTweet;
?>
Hope this helps you in your web development. As always, please feel free to leave any comments or suggestions.

MySQL Database Interaction PHP Class

There are many ways out there to connect to a database, but there is only a few of them that are effective. This is the MySQL object that I use to connect to a database via PHP. You will find this class to be simple but very effective as it’s not overfilled, but it only contains what it’s needed in order to compile a successful application. I have used it multiple times in tasks that include from basic user managements to custom cloud application development. From connecting to a single database, to multiple databases.

Here is the code, please make sure to replace the values of the variables so that you can successfully connect to your database.

class db
{
//Object Variables Please Replace, you can also have them set on the constructor so that you can connect to multiple databases.
private $status;
private $host = ‘localhost’;
private $database = ‘db_name’;
private $username = ‘username’;
private $password = ‘password’;
public ξ$result;
public ξ$results;
function __construct(){
//Connect To Database
$this->status = mysql_connect($this->host,$this->username,$this->password) or die (‘Cannot Open Conection to ‘ .
$this->host);
//Select Database
mysql_select_db($this->database,$this->status);
}
function query($sql){
//Get Results
$this->result = ξmysql_query($sql);
}
function fetch($sql,$type){
//Perform Query
$this->query($sql);
switch ($type){
//Fetch as an Array
case ‘array’:
$this->results = mysql_fetch_array($this->result);
break;
//Fetch as an Asspciative Array
case ‘assoc’:
$this->results = mysql_fetch_assoc($this->result);
break;
//Fetch as an Object
case ‘object’:
$this->results = mysql_fetch_object($this->result);
break;
}
//Return Results
return $this->results;
}
function checkit($sql){
//Check Table for Query
return mysql_num_rows(mysql_query($sql));
}
function __destruct(){
//Free Query Result
mysql_free_result($this->result);
//Close DB Connection
mysql_close($this->status);
}
}

Please let any comments, suggestions orξrecommendationsξon the area below.

error

Enjoy this blog? Please spread the word :)