$mail send php
The classic PHP mail function!
In PHP, you can send an email using the mail()
function, which is a built-in function that allows you to send emails from your PHP script. Here's a basic example:
<?php
$to = '[email protected]';
$subject = 'Test email from PHP';
$message = 'This is a test email sent from PHP.';
$headers = 'From: [email protected]'. "\r\n".
'Reply-To: [email protected]'. "\r\n".
'MIME-Version: 1.0'. "\r\n".
'Content-Type: text/plain; charset=UTF-8';
mail($to, $subject, $message, $headers);
?>
In this example:
$to
is the recipient's email address.$subject
is the subject of the email.$message
is the body of the email.$headers
is an array of headers that specify the sender's email address, reply-to email address, MIME version, and content type.
The mail()
function takes four arguments:
$to
: The recipient's email address.$subject
: The subject of the email.$message
: The body of the email.$headers
: An array of headers.
When you call the mail()
function, it will send the email to the specified recipient using the default mail server settings on your server.
Note that the mail()
function is a simple function that does not provide any error handling or logging. If the email fails to send, you will not receive any error messages. To improve the reliability of your email sending, you may want to consider using a more advanced email library or service, such as PHPMailer or Sendgrid.
Also, keep in mind that the mail()
function is not suitable for sending large amounts of email or for sending emails to a large number of recipients. In such cases, you may want to consider using a more advanced email service or library that provides better performance and scalability.