How to make php mail

How to Send Email with PHP: Learn to use mail() to send emails with PHP, including an example.

Setting up PHP mail

Sending emails using PHP is an easy task. It is possible to send emails from a web application using the PHP mail function. Here, we will look at how to set up a basic PHP mail script.

The first step is to set up some basic variables. These will include a "from" address, a "to" address, a subject line and a message body:

$from = "[email protected]";
$to = "[email protected]";
$subject = "PHP email test";
$message = "This is a test message";

Now, we can use the PHP mail function to send the message. This function takes four parameters:

mail($to, $subject, $message, $from);

It is also possible to add headers to the message, such as a "reply-to" address or a "cc" address. This can be done by adding an additional parameter to the mail function:

$headers = "Reply-To: [email protected]";
$headers .= "Cc: [email protected]";

mail($to, $subject, $message, $from, $headers);

Finally, it is also possible to set additional mail parameters, such as the mail priority or the content type of the message. This can be done by setting the additional_headers parameter:

$additional_headers = "X-Priority: 1rn";
$additional_headers .= "Content-type: text/plainrn";

mail($to, $subject, $message, $from, $headers, $additional_headers);

That's all there is to setting up a basic PHP mail script. With a few lines of code, it is possible to send emails from a web application using PHP.

Answers (0)