Sending Email Including HTML / Text / Attatchments using PHP

As you know today email is mostly frequently being used more than a phone till now, if you subscribe any one using your email then you will get tons and tons of message that your girl friend will also not sent you that much message ;) .

Today i am going to show you, how to send automated email who signup into your website. Generally sites which you have signed up will send you a automated welcome email. This is using php script. I have divided my tutorials into three different sections.

  1. First sending simple email
  2. Sending email with attachment
  3. Sending Email with HTML

To work this automated sending email message you need to have live working server where you will upload your file. For windows machine you need to set-up SMTP function into your message.

 

Sending Simple Email

If you have been familiar with PHP then you might know that there is already a function name mail() which holds some basic and optional parameters. They are in order like to whom to send and email generally send to, message to be sent and additional headers if we want to include it in our email.

The mail()  functions returns true” if message sent otherwise will return false. Check this code as an example :-

 

Sending Email with Attachment

As above code is just for simple text mail. Now i will show you, how to send an email with attachment. It is really helpful when you need to send images and photos to others. To do this we have to use Multi part or mixed type MIME to send both text based email or HTML based email along with attachment. Look the code below for an example :-

 

Sending Email with HTML format

Some web email services doesn’t recognize the language format so, if we write just the way you like they don’t understand the code and display as  the text is which is without formatting. Therefore we need to use multi part construction to send email, where one part contains text and other as html codes. Take a look for below example.

Check this by implementing into your webpage and let me know if it worked..!!! I will get back for solution of the problems.

If you enjoyed this post, make sure to subscribe to tribiablog's RSS feed.