On Unix systems, you can configure the mail() function to use sendmail or Qmail to send messages. When running PHP under Windows, you can use sendmail by installing sendmail and setting the sendmail_path in php.ini to point at the executable. It likely is more convenient to simply point the Windows version of PHP to an SMTP server that will accept you as a known mail client:
Syntax of mail function
mail(
string $to
,
string $subject
,
string $message
,
array|string $additional_headers
= [],
string $additional_params
= “”
): bool
About mail parameters
to
Receiver, or receivers of the mail.
Example :user@example.com
subject
Subject of the email to be sent
message
Message to be sent.
Each line should be separated with a CRLF (\r\n). Lines should not be larger than 70 characters
Example of mail function to send mail in PHP
<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('caffeinated@example.com', 'My Subject', $message);
?>
More example to send mail
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = array(
'From' => 'webmaster@example.com',
'Reply-To' => 'webmaster@example.com',
'X-Mailer' => 'PHP/' . phpversion()
);
mail($to, $subject, $message, $headers);
?>