Php mail format
The PHP mail format!
In PHP, you can send emails using the mail()
function, which takes several parameters to format the email. Here's a breakdown of the format:
mail($to, $subject, $message, $headers)
$to
: The recipient's email address (required)$subject
: The subject of the email (required)$message
: The body of the email (required)$headers
: An optional string containing additional headers (e.g., From, To, CC, BCC, etc.)
Here's an example of a basic email format:
<?php
$to = '[email protected]';
$subject = 'Hello from PHP!';
$message = 'This is a test email sent from PHP.';
$headers = 'From: [email protected]'. "\r\n".
'Reply-To: [email protected]'. "\r\n".
'Content-Type: text/plain; charset=UTF-8';
mail($to, $subject, $message, $headers);
?>
In this example:
$to
is the recipient's email address ([email protected]
)$subject
is the subject of the email (Hello from PHP!
)$message
is the body of the email (This is a test email sent from PHP.
)$headers
is a string containing additional headers:From: [email protected]
specifies the sender's email addressReply-To: [email protected]
specifies the reply-to email addressContent-Type: text/plain; charset=UTF-8
specifies the email format (plain text) and character encoding (UTF-8)
You can also use the headers
parameter to specify additional headers, such as:
CC
(carbon copy) orBCC
(blind carbon copy) recipientsMIME-Version
andContent-Type
for attachments or HTML emailsDate
andFrom
for setting the email's date and sender information
Here's an example with additional headers:
<?php
$to = '[email protected]';
$subject = 'Hello from PHP!';
$message = 'This is a test email sent from PHP.';
$headers = 'From: [email protected]'. "\r\n".
'Reply-To: [email protected]'. "\r\n".
'CC: [email protected]'. "\r\n".
'BCC: [email protected]'. "\r\n".
'MIME-Version: 1.0'. "\r\n".
'Content-Type: text/plain; charset=UTF-8'. "\r\n".
'Date: Mon, 27 Jul 2020 14:30:00 +0200'. "\r\n".
'From: John Doe <[email protected]>';
mail($to, $subject, $message, $headers);
?>
Remember to replace the placeholders ($to
, $subject
, $message
, and $headers
) with your actual email data.