PHP 8 - Send Email

Last modified: April 02, 2022

What to send email from your PHP Website?

<?php mail(to,subject,message,headers,parameters); ?>

PHP mailer uses Simple Mail Transmission Protocol (SMTP) to send mail. On hosting place, this is already setup but in Virtual, dedicated VM and in our development PC, we need to setup the SMTP. If we do not, email might not send or send to Junk email.

  • The SMTP mail settings can be configured from “php.ini” file in the PHP installation folder.

  • Go to C:\xampp\php folder and find php.ini file

  • Edit php.ini file and find

  • sql

    • if your SMTP server need authentication, add below lines
    • auth_username = [email protected]
    • auth_password = example_password
  • Restart the Apache server, in our case we stop Apache Server and Start Again in XAMPP Control Panel

  • sql

Now we can send email

<?php $to_email = '[email protected]'; $subject = 'Hello'; $message = 'This is a test email'; $headers = 'From: [email protected]'; mail($to_email,$subject,$message,$headers); ?>