PHP Mail Function
Can You explain me about how to send mail through php mail function?
Assuming that you have the basic configuration done for mailing, you could simply use the PHP mail function as follows -
mail( $to, $subject, $message, $headers, $parameters);
Headers and Parameters are optional, and need to be used depending upon the kind of functionality you need. Does this answer your question?
PS: I'd recommend using a dedicated library for mailing - PHP Mailer.
mail function won't work on localhost, you can use phpmailer library to send emails using 3rd party smtp such as gmail, sendgrid or elastic
Use mail() and be sure to add headers like mailer, from, reply to, to, if possible add security headers. This function doesn't work on localhost if it doesn't connect to outbound port. If you have setup port forwarding or dynamic dns it will work.
The mail() function allows you to send emails directly from a script.
First you need to download the library PHPMailer. create a new folder where you have your index file and copy paste the files after downloading to the new folder. You need to specify the Gmail account where you want to send gmail.
$mail = new PHPMailer();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = '465';
$mail->Username = 'your email address';
$mail->Password = 'gmail password';
$mail->Subject = 'Hello World';
$mail->Body = ' An email example';
By running the above code you can send image to the receiver.