How to Send Text and HTML Emails in PHP – Tutorial Republic

In this tutorial you will learn how to send plain text or html emails directly from script using the php mail() function.

php mail() function

Sending email messages is very common for a web application, for example sending a welcome email when a user creates an account on your website, sending newsletters to your registered users or obtaining comments or feedback from users through the website’s contact form, etc. activated.

You can use PHP’s built-in mail() function to create and send email messages to one or more recipients dynamically from your PHP application, either in plain text or html format. the basic syntax of this function can be given with:

The following table summarizes the parameters of this function.

send plain text emails

The easiest way to send an email with php is to send a text email. In the example below, we first declare the variables (recipient’s email address, subject line, and message body), then pass these variables to the mail() function to send the email.

send emails with html format

when you send a text message using php, all content will be treated as plain text. let’s enhance that result and convert the email to an html formatted email.

To send an html email, the process will be the same. however, this time we need to provide additional headers as well as an html-formatted message.

See Also:  How to Create a Free Gmail Address (Google Mailbox Account)

In the next two chapters (php form handling and php form validation) you will learn how to implement an interactive contact form on your website to receive user comments and feedback via email using this send mail feature php.

Leave a Reply

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