php.ini & SMTP= - how do you pass username & password

To pass a username and password to the SMTP server in the php.ini file, you can use the following format:

SMTP = smtp.example.com
username = your_username
password = your_password

You can also specify the port number if it is not the default port (25):

SMTP = smtp.example.com:587
username = your_username
password = your_password

Watch a course Learn object oriented PHP

Keep in mind that the php.ini file is read by PHP when it is starting up, so you will need to restart the web server for these changes to take effect.

You can also pass the username and password as arguments to the mail() function if you don't want to store them in the php.ini file. For example:

$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

mail($to, $subject, $message, $headers, '[email protected] -Xusername:password');

The -f and -X options are used to specify the "envelope from" address and the SMTP authentication credentials, respectively.