PHP General Tips
In this tutorial you will learn some general tips on PHP programming - debugging common errors in PHP, sending HTML formatted message in PHP, sending and receiving HTML mail messages.
- Common Errors in PHP
- Sending HTML text in PHP mail
- Using Multiple Check boxes with same name
- Including a file in PHP
- Common Code for Linux, Unix, Windows
1. Common Errors in PHP
'Warning: Cannot modify header information - headers already sent by (output started at filename line no __) '
If you run a PHP document get the above error message, it means that an error has occured in your php document. This takes place if there are any executable statements like echo before the set cookie or session variable. Try to find the statement and remove it and then run the same program.
2. Sending HTML message using PHP mail function
If you want to send HTML text message in the mailbody without any instruction in the mail function it can be done as follows using the PHP mail function.
$strFrom="baskar@smartwebby.com";
$strTo="mail@smartwebby.com";
$strSubject="Sending HTML text in php mail";
$strMailbody="mailbody<br>Welcome to <a href="www.smartwebby.com">smart webby</a><br><br><b>Best Regards</b><br><b>SmartWebby";
Mail function for HTML message format is as shown below:
Mail Function:
mail($strTo,$strSub,$strMailbody,"From:$strFrom/r/nReply-to:$strFrom);
When sending mail using the above format, you'll receive a mail in plain text as shown below.
From:baskar@smartwebby.com To:mail@smartwebby.com
Subject:Sending HTML text in php mail
mailbody<br><a href="www.smartwebby.com">Welcome to smart webby</a><br><br><b>Best Regards</b><br><b>SmartWebby
So we send the HTML text in the mailbody using the following statement
mail($strTo,$strSub,$strMailbody,"From:$strFrom\r\nReply-to: $strFrom\r\nContent-type: text/html; charset=us-ascii");
Ouput for the above format is as shown below:
From:baskar@smartwebby.com To:mail@smartwebby.com
Subject:Sending HTML text in php mail
mailbody
Welcome to smart webby
Best Regards,
SmartWebby