Posted in: PHP

How to Send Mail/ Email in PHP – PHP Mail Sending Script

Sending an enquiry form to your mailbox is very common now these days and you can see how much important it is. From a point of view of a business its a best and fast communication of getting the details of the customer as well as their need. In this post we will discuss about How to Send Mail in PHP, Submit Form Data and Email in PHP.

Today we discuss about how to Send the form at your mail box in PHP. Here we are providing the script with dummy text so you have to change those values with your values and check it.

Step 1. Creating Form for getting the details of the customer.

Step 2. Sending form data/value to PHP

Step 3. Get the Value in PHP Script

Step 4. Send Mail and Print Success

Step 1. Creating Form for getting the details of the customer.

In this step we create the HTML Form to get the data of the client/customer.

Now we have the form to submit ohohohoho wait !!!! but where to submit it. Check out  the Step 2

 

Step 2. Sending form data/value to PHP

After creating the form we will send this form to PHP. Lets assume that we have the PHP Email Script at the beginning of the page.  So we will put action in the <form> to send the form data to PHP script which is underlying somewhere in our page.

We will declare the action for same page.

When you click on submit it will send the value to same page and your PHP will take these values…. But how….. Lets move to Step 3

Step 3. Get the Value in PHP Script

Now after sending the value we will receive these values in our PHP Script to send the mail. By using the $_POST[“dataname”] we will get our value which was submited earlier. In $_POST[] we will pass the name of the text box. Now we will get all the four values in our PHP Script

After submitting we have all the four values in our four variables ………… But what to do with these values…… Check Step4.

Step 4. Send Mail and Print Success

Now we have the values in our variable’s and we have to just send these values to our email box yeeepiiiiii now we cant wait to do it……. but we have to work a little bit ………..may be there is no name or phone is missing or email is not there…. if any details is missing than it will be a mess so why we dont put some security over the submission of the form. We will check the Name,Phone and Email values if anyone is missing we will not submit the form and return an error message.

Now we will change the else part to submit it to our mail script and send these values to our Mailbox.

Lets check what happen to our mail is it sent or not. we will add some more code to our else part.

If you want to send mail to 2 3 persons than you can put the comma(,) and write the $to like this – “demo1@demo.com,demo2@demo.com,demo3@demo.com”

Or you can add BCC like – $header=”BCC: demo <demo@demo.com>” or $header=”BCC: demo@demo.com”

Now what ?????????? What are are you looking for we have completed our tutorial and worked a lot so have a cup of coffee or just go to bed for a Nap. Bye.

Thank You.

Comments (5) on "How to Send Mail/ Email in PHP – PHP Mail Sending Script"

  1. hello i am setting an image in title bar…..
    it works only in mozilla firefox but not working in other browsers….. could you please help me..
    thanks..

    1. Could you tell me what code you are using if you are using the fevicon icon than use below code in your section

      Remember that it will use the icon file only. if you dont have the icon than check below link to create it
      http://www.favicon.cc/

Leave a Reply

Your email address will not be published. Required fields are marked *