Send email using PHP script

A basic and simple article for the beginners who want know about how to to send email using php.

In this article, we will use HTML form to get data from the user and send an email using PHP script. PHP mail() function is used to send an email. We can send both simple/text emails and also HTML emails. First, we will learn about how to send email using PHP.

HTML form

Following is the HTML form which will be used to fill the required data.

Send email using php

Following is the script which will be used to send an email using PHP. Create new file named as “process_email_form.php” for script.

The above script initially get the form data and then applies check on them if any field was left empty. Finally, mail() function is used in order to send email using php script.

This was all about sending simple text email and using mail() function. You can play with the code to add validation and error checks.

Next article will be about sending HTML email in PHP.

Other related articles:

use php mail functions to send email



Read More

Upgrade PHP version in WAMP

One can easily upgrade PHP version in WAMP manually. WAMP allows you to have multiple versions of php and you can choose any one of them to be used.

Following are the steps to be followed for upgrading php version in WAMP.

  1. Download version of PHP for Windows.
  2. Extract and place the folder in wamp/bin/php/
  3. Give the folder name according to downloaded version
  4. Copy 3 important files from existing version of php and paste them into new PHP version folder.
  5. Open php.ini file and correct the version of PHP where required


1. Download version of PHP for windows

Zip file of PHP version can be downloaded from PHP version for Windows. Download thread safe version.


2. Extract and place the folder in wamp/bin/php/

Extract the downloaded zip file of php version and place that into wamp/bin/php/ folder.


3. Give the folder name according to downloaded version

Now rename the folder and give it the name according to the downloaded version of PHP. For example, If you have downloaded PHP version 5.6.13 so give it a name php5.6.13


4. Copy 3 important files from existing version of PHP and paste them into new PHP version folder

The 3 important files to be copied from existing PHP version to new folder are:

  1. php.ini
  2. phpForApache
  3. wampserver.conf


5. Open php.ini file and correct the version of PHP where required

You need to change the php version in php.ini file. For example, extension_dir needs to be changed. If php.ini was copied from php5.4.3 so you will have to change extension_dir path from c:/wamp/bin/php/php5.4.3/ext/ to c:/wamp/bin/php/php5.6.13/ext/. Also find this sort of change if required within php.ini file and update them.


Now new version is ready to be used. Exit the WAMP and open it again. Stop all services and select the PHP version from PHP version menu as show below. Now Restart All Services.



To verify the version of PHP running on your local server, open localhost in web browser and then click on phpinfo.




Read More

Day number of week from date or day in php

In one of the previous posts I described how to get day from date in PHP. The same function can be used to find the day number of the week. In this post I have given examples of how to find “day number of week” from both date and day name.

For example:

20/8/2015 is Thursday, which is 4th day of the week.


Find current day number of week


Find day number of week from date


Find day number of week from day

Other than date, day number of week can also be found by the “date name”.



Useful Links:

day of the week to day number

Finding the number of the day in a week in PHP from a date

Read More


Here is a very helpful function in php through which you can push data into array. Data will be inserted at the end of array, just like in the stack.

The function is array_push()


How to push data in array PHP

If you save some data into array;


$arr = array(“a”,”b”);


and now you can easily add other data into it using array_push() function as follows.




Now to verify this you can simply use print_r() function.





Output clearly shows that data elements “c” and “d” have been pushed into array “$arr”.

Useful Links:

PHP Manual for array_push

Read More


It is very simple to find or get day from date in php. This posts shares very simple example of how to get day from date or week-day from date-time using PHP. Covert date-time string to time and use date function as mentioned in the following code chunk



Read More


If you want to subtract time from the date, it is very simple in PHP.
There exist number of ways to subtract time in PHP. Following codes chunks shows how you can subtract time from date or date-time in PHP.



Read More


This post describes how easily you can test the connectivity or ping ip and port using PHP. Function to be used is fsocketopen .

Function prototype is follows:

fsocketopen(host, port, errorno, errorstr, wait_timeout_in_seconds)



Read More