Example of Mail Or Email In PHP With HTML
Php / / July 04, 2021
When we need to send an email or email from our website, we use a programming language, with the function PHP mail () we can send emails without the need to have a mail client installed on an apache server or anyone that supports this function, its syntax is very simple:
Code:
mail ($ recipient, $ subject, $ body);
If we use it in this way, it will arrive without format, that is, only text, but what happens when we want to send the mail with format, tables or images.
For this we will use the last parameter of this function, which is where we can send headers and indicate that it is a file with html code to process it as such.
And just by adding the following line we will have our email with format and code in html.
Code:
Content-type: text / html
In the end our function will be as follows:
Code:
mail ($ recipient, $ subject, $ body, ’Content-type: text / html’);
This would be a example of mail in PHP with HTML format:
Code:
php
$ destination = "[email protected]";
$ subject = "Web contact";
$ headers = "Content-type: text / html"; b>
$ body = "Hello, someone has contacted by the Web form of your site
The data sent are the following:
Name: $ name
email: $ email
And send the following comment:
";
$ comment
mail ($ destination, $ subject, $ body, $ headers); < br /> echo "The message has been sent correctly ";