Wednesday 27 March 2013

Determine execution time in PHP File


Determine execution time in PHP File


This code will determine the time taken for a php script to execute correct to 0.000000000000001 seconds.

<!-- put this at the top of the page --> 
<?php 
   $mtime = microtime(); 
   $mtime = explode(" ",$mtime); 
   $mtime = $mtime[1] + $mtime[0]; 
   $starttime = $mtime; 
?> 

<!-- put other code and html in here -->


<!-- put this code at the bottom of the page -->
<?php 
   $mtime = microtime(); 
   $mtime = explode(" ",$mtime); 
   $mtime = $mtime[1] + $mtime[0]; 
   $endtime = $mtime; 
   $totaltime = ($endtime - $starttime); 
   echo "This page was executed in  ".$totaltime."  seconds"; 
?>




Thursday 7 March 2013

Sending HTML Email through PHP

Sending HTML Email through PHP uses the exact same mail function as text email:



<?php
// PREPARE THE BODY OF THE MESSAGE

$message = '<html><body>';
$message.= '<img src="your image" alt="Email Template" />';
$message.= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message.= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>PatrioSys</td></tr>";
$message.= "<tr><td><strong>Email:</strong> </td><td>email@email.com</td></tr>";
$message.= "<tr><td><strong>Your Text:</strong> </td><td>Hello</td></tr>";
$message.= "<tr><td><strong>Comment:</strong> </td><td>Welcome</td></tr>";
$message.= "<tr><td><strong>TEST:</strong> </td><td>SUCCESS</td></tr>";
$message.= "</table>";
$message.= "</body></html>";
          
//   CHANGE THE BELOW VARIABLES TO YOUR NEEDS
         
$to = 'softmanicadmin@gmail.com';
//Subject of your Mail
$subject = 'Send HTML Mail Using PHP';
$headers = "From: yourmail@gmail.com\r\n";
$headers.= "Reply-To: CCmail@gmail.com\r\n";
$headers.= "MIME-Version: 1.0\r\n";
$headers.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//This function will send mail
if (mail($to, $subject, $message, $headers)) {
echo 'Your message has been sent.';
} else {
echo 'There was a problem sending the email.';
}

?>

That's it!