HTML Email Newsletters Coding

Email Newsletter

HTML email newsletter coding rules

Are you getting irritated when your email newsletter looks different in browsers and inbox? follow the rules explained here to make better email newsletter.
  • Use table for everything. Don’t try to use Div. Enclose the hole newsletter in a table.
  • You have to use inline CSS only. External CSS won’t work in newsletter. And CSS should be inside body tag. Don’t use CSS inside Head tag.
  • Don’t use any shorthand in CSS. Use abbreviated styles. For example: Use color:#ffeedd instead of color:#fed
  • Avoid using Divs and Spans. Try to use tables for everything
  • Padding won’t work in newsletter. So use margin only. specify the margin like margin-left, margin-right, margin-bottom
  • Don’t use header (h1, h2, h3, h4, h5, h6)>. Because some mail providers has their own design for this tags.
  • If you want right alignment for image, put it in a table and give cellpadding=’0′ and cellspacing=’0′
  • Store images on web server and use them. Don’t delete the stored image.
  • Avoid Line-height in CSS

Get URL and change the according image in PHP


change image according to url

Trick to change image according to URL in PHP

Hi people! This trick is pretty simple and very useful at sometimes.
Sometimes you might want to change image according to URL in any PHP page here is the tutorial.

STEP1

In first step you need to get the current url. See the code below
This code is a php function which allows you to find out the current page URL.
You can get the Current page URL like this
This will print the current page URL. But for this tutorial we need to store it in a variable.
We’ve stored the current page URL in the variable ‘$cur’.

Step 2

Now we need to split the URL according to ‘/’ and have to select the last part.
Note: if your URL is something like this ‘http://www.example.com/pages/about’ you’ve to use the above code as it is, but if your URL is Like this ‘http://www.example.com/pages/about/’ you’ve to change the ‘-1′ to ‘-2′.
The above code will store last part of the URL in the variable $url for example ‘about’.

Step 3

Now all you need to do is save an image in this name. eg. ‘about.jpg’
Then go to your page and put the following code where you want your image to be placed.
Hurrah!! if you go to that page you can see your image. Now include all the above codes into each page where you want to show the images and place the image with the same name of URL’s last part.

PDF generater in PHP tutorial

php pdf

PHP PDF Generate tutorial

Here is the tutorial for php pdf creation.
For this you need to download a file called fpdf.php

Basic Code to generate pdf in php

Take a look at the code, First you need to include the fpdf.php file using require() function.
after requiring the library file, we instantiate an object of the FPDF class and call it $pdf.
Then we add a page with the AddPage method, set our output font, define the cell (location) for our string of output, and then—using the Output method—display the PDF in the browser.
Output for the above code will be
php pdf

PHP PDF generate using cell

In the above code we’ve used cell method.
For the first text “PHP – The Good Parts!” we’ve given x=10 and y=10 and 0,0,’L’ denotes column, row and text alignment respectively.
So the output will be
php pdf

NOTE:

You may want to disable your browser’s caching capabilities while you are developing and testing the layout of your FPDF PDFs because some browsers will not reload the page with changes if the changes are so small that they don’t register as such with the cache control.

Attachments

1) FPDF.php

Top 20 PHP Tips and Tricks for beginners

PHP tips

PHP tips to improve PHP skills

Hi people, in this post i’m gonna deliver you some interesting quick tips to explore and improve PHP skills. Try to follow these tips when you code.
  1. Use <?php ... ?> tags for PHP. All other formats are depreciated including short tags.
  2. It is very useful to use Unset or null your variables to free memory, especially for large arrays.
  3. It is better to wrap you strings in single quotes (”) instead of double quotes (“”). Beacuse PHP looks for variables into double quotes.So unless you’re gonna use a variable inside, don’t use doubles quotes for variables.
  4. echo is faster than print. So avoid using ‘print’ often.
  5. else if” statements are faster than select statements aka case/switch.
  6. Use sprintf instead of using variables contained in double quotes, it is about 10x faster.
  7. Turn on mod_deflate in Apache v2 to reduce the use of bandwidth. For Apache v1 try mod_gzip.
  8. Avoid using string concatenation. Preferred method is echo’s multiple parameters (or stacked).
  9. Avoid using pre-calculated functions in loops. for eg. for($i=0; $i< count($array);$i++) This will call count function each time. So store it in a variable like this $count = count($array); before the loop starts.
  10. Avoid using magic methods like __isset(), __unset(), __sleep().
  11. Avoid require_once() and use require() where possible.
  12. Better to Use full paths in includes and requires.
  13. require() and include() are same in all the ways. One different is require will halt if the file is missing. Performance wise there is a very little difference between them.
  14. Since PHP5, the script execution start time can be found by $_SERVER[’REQUEST_TIME’], so avoid using time() or microtime().
  15. PCRE regex is quicker than EREG, but always look out if you can use quicker native functions such as strncasecmp, strpbrk and stripos instead.
  16. Try xml2array when parsing XML in PHP, which makes use of the PHP XML functions, for HTML you can try PHP’s DOM document or DOM XML in PHP4.
  17. Error suppression with ” @ ” is very slow.
  18. str_replace is faster than preg_replace. str_replace is best overall, however strtr is sometimes quicker with large strings. Using array() inside str_replace is usually quicker than multiple str_replace.
  19. $row[’id’] is 7x faster than $row[id], because if there is no quotes PHP has to guess which index you meant, assuming you didn’t mean a constant.
  20. It is always better to close your database connection after the use.

PHP form handling for beginners

PHP form handling

PHP form handling Tutorial

PHP form handling is the thing which irritates you if you’re a beginner.
The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.
Example
The example below contains an HTML form with two input fields and a submit button:
When a user fills out the form above and click on the submit button, the form data is sent to a PHP file,
calledwelcome.php“:
“welcome.php” looks like this:
Output could be something like this
Welcome John!
You are 28 years old.

The PHP $_GET and $_POST functions will be explained in the next chapters.

Form Validation

User input should be validated on the browser whenever possible (by client scripts). Browser validation is faster and reduces the server load.
You should consider server validation if the user input will be inserted into a database. A good way to validate a form on the server is to post the form to itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error.
The built-in $_GET function is used to collect values in a form with method=”get”.

The $_GET Function

The built-in $_GET function is used to collect values from a form sent with method=”get”.
Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser’s address bar) and has limits on the amount of information to send (max. 100 characters).
Example
When the user clicks the “Submit” button, the URL sent to the server could look something like this:
http://www.voidtricks.com/welcome.php?fname=Peter&age=37
The “welcome.php” file can now use the $_GET function to collect form data (the names of the form fields will automatically be the keys in the $_GET array):

When to use method=”get”?

When using method=”get” in HTML forms, all variable names and values are displayed in the URL.
Note: This method should not be used when sending passwords or other sensitive information!
However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases.
Note: The get method is not suitable for large variable values; the value cannot exceed 100 characters.
The built-in $_POST function is used to collect values in a form with method=”post”

The $_POST Function

The built-in $_POST function is used to collect values from a form sent with method=”post”.
Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.
Note: However, there is an 8 Mb max size for the POST method, by default (can be changed by setting the post_max_size in the php.ini file).
Example
When the user clicks the “Submit” button, the URL will look like this:
http://www.voidtricks.com/welcome.php
The “welcome.php” file can now use the $_POST function to collect form data (the names of the form fields will automatically be the keys in the $_POST array):

When to use method=”post”?

Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.
However, because the variables are not displayed in the URL, it is not possible to bookmark the page.

The PHP $_REQUEST Function

The PHP built-in $_REQUEST function contains the contents of both $_GET, $_POST, and $_COOKIE.
The $_REQUEST function can be used to collect form data sent with both the GET and POST methods.
Example

www.comhttp.blogspot.in. Powered by Blogger.