How to Send HTML Email via PHP Mail

How to Send HTML Email via PHP Mail thumbnail
You can send HTML email via PHP mail.

Email has become an ubiquitous form of communication that anyone can use. Programmers also use email to provide information to their users from software applications. In PHP, this can be accomplished by using the built-in "mail" function. For example, when signing up for membership on a website, a web application can send a confirmation email to the address a user specifies. Often those emails coming from applications will need to be branded according to company guidelines. To achieve the richness of fonts, colors, and images, you'll need to use HTML in your emails.

Instructions

    • 1

      Write your HTML message in your favorite PHP editor or text editor near the top of your PHP file after the opening PHP tag. Assign it to a variable:
      $message = "This is an <strong>HTML Message</strong>!";

    • 2

      Copy and paste the following line below the line from Step 1. This will actually send the mail with the message you specified:
      If (mail ("email_to@example.com", "Subject Line", $message))
      echo "Message Sent!";
      else
      echo "Message Failed!";

    • 3

      Upload your PHP file to your server using your favorite FTP client, then open the file in a browser to execute it. You should see a message indicating whether it worked or not on the page itself, and you'll get a confirmation email at the address you specified if it did. The email usually arrives within a few seconds. However, if you are on a busy web server, the message may take a couple minutes to arrive.

Tips & Warnings

  • To add the optional "from" and "reply to" headers to your HTML message, simply change the line in Step 2 to:

  • mail ("email_to@example.com", "Subject Line", $message, "From: person@example.com\r\nReply-To: person@example.com")

Related Searches:

References

  • Photo Credit email @ image by Witold Krasowski from Fotolia.com

Comments

You May Also Like

Related Ads

Featured