php email

php email


If you are web developer then you know how important is develop send html email functionality in a project. Using php email sending isn’t difficult now a days.

By writing just few lines of code, we can using php send email by just one click.

If you are looking for some html email example then you’ll love this article.

It is very simple php script that will make your task very easy.

1PHP Email send from localhost/server

1.Create PHP File

First create a simple PHP file using your text editor and gave it name index.php (you can give any name).

So now to send html email create contact form using html.

2. Get user data using PHP

User will fill the form and hit submit button so in this step we will receive users submitted data.

We can submit Form using two method GET and POST.

Don’t use POST method to submit form. here we had used POST method to submit the form.

Below is simple PHP script to receive user input which will executed after the submitting the form.

We have now users submitted data in our PHP variable.

Use PHP mailer to send email

3. Include PHP Mailer

PHP mailer is email sending library for PHP.

This library is open source and we can use this library to send email from PHP on localhost or server.

You can download PHP Mailer from Here.

After downloading PHP mailer and extract into your project folder.

For this tutorial am extracting PHP mailer into phpmailer folder.

I had added this two lines on top of my index.php file.

4. Send Email

In this final step we are going to send email using php mailer.

We download PHP mailer script, extract into our project, included on top of our page. now before sending email we have to configure our SMTP.

Here is how to configure SMTP to send email from php.

Configure Admin email address, add CC and BCC.

This line is used to tell PHP mailer every email should be send using

This line is to decide which email address will receive emails.

Now we had configure SMTP, already wrote the PHP code to store user input into PHP variable.

So, Here is final few lines of code for sending email.

We had already saved user input into a variable and now we are sending users data into table format.

Above code will send html email to (because in our tutorial we had set receiver email .

In your code replace with with your email address.

Final Words

This was the simple send html email code. For sending email from localhost or server.

In Our next article we will look send email with attachment example.




Please enter your comment!
Please enter your name here