Send Email using php from html Contact Page – Website Design Step 5

Spread the love

Send Email using php from html Contact Page: Friends, we already know that the contact-us page of a website plays a very important role in making the website user friendly. The user can contact the helpline about his problem from this contact page. From here the helpline helper can understand the problem of the user.

In Step 4 of Website Design and Development Session, we learned how to create a contact page using HTML and CSS. Friends, if you have not seen the previous step, then you must read the previous article in full, then it will be useful for you to understand the whole point of this article.

Also Read: How to Create HTML Contact Page -Website Design Step 4

In today’s article we will learn “how to send email using PHP code“. This code is used to create contact pages on all company websites. Only contact forms can be created via HTML and CSS. But if we want to send an email from that contact form to any email usage we must need php.

You must see that if you submit all the details in the contact form of a website, From time to time an email arrives on your email id. And that email says your problem has reached them and they will try to solve your problem as soon as possible.

Send Email using php

In today’s article, we have just reached out to the subject of user problems. In that regard, we will create a system to send a confirmation email to the user using php code. Send Email using php.

What is php?

The full name of PHP is Hypertext Preprocessor. php is a server-side language which means that when the php code is run, the code is run on the server-side and the results are displayed in the browser in html code. php interview questions for 5 years experience.

We need a server to run PHP code. We are working on this web design and development session live server so we do not need any other separate server for this.

How to create PHP file?

I hope you guys think we learned how to create files in the first step of this website design and development session. That is, we already know how and where to create HTML, CSS, JavaScript, PHP files. Here’s a brief look at how to create a PHP code file to remind you again. Similarly, to create all the pages we need today, we need to login to our web hosting cPanel.

After logging in to cPanel we need to open the” file manager” option then from there we need to open the folder of “public_html“.

After login in to cPanel -> Click file manager -> Click public_html -> Click on +File from menu bar -> Enter file name(sendemail.php) -> Click Create New File.

php New file Create Process

Send Email using php

We have named our php file here “sendemail.php“. Now we need to add all the php codes that are required to send to the email id of the email user in this sendemail.php file. To add php code to this file, we need to edit this file. Below is the process of editing this file.

Right click on sendemail.php -> Click Edit option -> Again click Edit option -> Then This sendemail.php  file editor open new tab.

How to edit sendemail.php file?

mail("","Subject","Your Massage");

    $to      = '';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From:' . "\r\n" .
               'Reply-To:' . "\r\n" .
               'X-Mailer: PHP/' . phpversion();

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

Here the details of this Send Email using php from html Contact Page code-

  • $to – The email ID of the person we want to send the email to will be here.
  • $subject – Here you have to write the subject for which the email is being sent.
  • $message – Here you have to write the whole thing for which you want to send email.
  • $headers – It is used where it is mentioned where the email came from and in order to give feedback on this email you have to specify the email id.
  • mail($to, $subject, $message, $headers); – This code sends all the contents of the email to the user.

Save the above code by copying and pasting it into your PHP file and run the page once to see if the page is working properly.

Send Email using php

Send Email using php from html Contact Page

Now to send email to user email from our contact page we need to add our html to our php file so let’s see how to add.

Also Read: How to add Simple html Page in our website – Website Design Step 3

This is our contact.html file. Here we need to change the coding a little bit. The place I need to change, I have bolded here. We need to attach our PHP code file to the HTML page “action” page is “sendemail.php”. We will send all user data from our HTML page to the PHP file via the “POST” method.

Step -1 

<form action="sendemail.php" method='POST'>
<center><font size='6' face='Rockstar-ExtraBold'><strong><u>Contact with us </u></strong></font></center>

<input name='name' type='text' required placeholder='Enter your full name'>
<input name='mobilenumber' type='number' required placeholder='Mobile number'>
<input name='email' type='email' required placeholder='Your Email id'>
<textarea name="message" placeholder="Message" required</textarea>

<div align='center'>	
<input name='submit' type="submit"  
				style='	float: center;
						height: 39px;
						overflow: hidden;
						margin: 0px 0 0 0px;
						padding: 0 25px;
						outline: none;
						border: 0;
						font: 300 15px/39px ;
						text-decoration: none;
						color: #fff;
						cursor: pointer;

And this is the final code of our PHP that will be used to send emails to users. This page will collect all the data sent from the HTML page and send it to the email user via php.

Step -2

$name         = $_POST['name'];
$mobilenumber = $_POST['mobilenumber'];
$email        = $_POST['email'];
$message      = $_POST['message'];

    $to      = $email; // User emailid
    $subject = 'You can write the subject here as per your requirement';
    $message = "Name- ".$name."\r\nMobile No-".$mobilenumber."\r\n\r\nYour query - ".$message."";
    $headers = 'From:' . "\r\n" .
               'Reply-To:' . "\r\n" .
               'X-Mailer: PHP/' . phpversion();

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

Now we will run the Contact.html page on our website and for example type any username, mobile number and email id and message and submit the page to see if our code is working properly i.e. we have email or not.

Send Email via php

Friends, I hope that by following these steps, you will be able to successfully create a contact page for your website. It is seen in many websites that the designers of that website set up the communication page without any coding of the contact page only with the email id, mobile number and address.

Also Read: Responsive Navigation Menu CSS – Website Design Step-2

You can create contact pages for your website in this way if you want but my friends will comment if you create a website with HTML, PHP, JavaScript, CSS then you must create (Send Email using php from html Contact Page) this kind of contact paste which will be user friendly for your website.

The last few words

I hope you like today’s article, be sure to share this article with your friends and family. If your contact page doesn’t work properly using the codes found in the article, be sure to let us know and we’ll try to get the coding right for you.

If you have any air ticket issues please let us know in the comment box and we will try to resolve your comment as soon as possible.

Spread the love

Leave a Comment