Install Config Wiki

All about installing, configuring and troubleshooting

User Tools

Site Tools


Sidebar

Wiki Topics

wiki:setup_smtp_in_php_ini_with_authentication

Setup SMTP Mail with Authentication in php.ini file on Windows IIS

  • Make sure that you install Notepad++ to your windows server because native Notepad Windows app won't work for this.
  • On the Windows web server, locate the PHP installation folder. Example c:\php\
  • Open the php.ini file using Notepad++ editor (right click php.ini and left click “open with” and select Notepad++).
  • Search for, add or modify the [mail function] section of php.ini as follows:
[mail function]
; For Win32 only.
; http://php.net/smtp
; SMTP = localhost  REM-OUT 10-28-2017 INSERT NEXT LINE INSTEAD
SMTP = your.mailservername.tld

; http://php.net/smtp-port
smtp_port = 25

; REMARK - INSERT NEXT TWO LINES TO AUTHENTICATE THROUGH EXISTING EMAIL ACCOUNT ON SMTP SERVER
auth_username = mailuser@yourdomain.tld
auth_password = password_of_your_mailuser

; For Win32 only.
; http://php.net/sendmail-from  REMARK - INSERT AND UN-COMMENT NEW LINE HERE BASED ON EXAMPLE
;sendmail_from = me@example.com
sendmail_from = no_reply@yourmaildomain.tld
  • Save the php.ini file with those changes.
  • Restart the World Wide Web service – Internet Information Services

Create a PHP Test Mailer File

  • In some web folder on your php-enabled web site, create a text file named “phpmailtester.php”
  • Open that file with Notepad++ and insert the following php code, but change your test recipient's email address.
  • Access the file from your website using any web browser.
  • Note: The page will be empty, but you should check your recipient email account to see whether the test mail arrived. Also view the headers or source code of the test email to see the route taken.
<?php
//REMARKS -sending email with the php mail() funtion
//REMARKS -THE COMMA-SEPARATED SINGLE-QUOTE 'DELIMITED' FIELDS OF THE mail() function BELOW: 
//FIELDS - mail('RECIPIENT_EMAIL','SUBJECT','BODY');
mail('recipient@somedomain.tld', 'Test Email using PHP', 'A message in the body of the test email');
?>

Download my example of phpmailtester.php file and modify it accordingly

phpmailtester.php
<?php
//REMARKS -sending email with the php mail() funtion
//REMARKS -THE COMMA-SEPARATED SINGLE-QUOTE 'DELIMITED' FIELDS OF THE mail() function BELOW: 
//FIELDS - mail('RECIPIENT_EMAIL','SUBJECT','BODY');
mail('recipient@somedomain.tld', 'Test Email using PHP', 'A message in the body of the test email');
?>
wiki/setup_smtp_in_php_ini_with_authentication.txt · Last modified: 2017/10/28 18:45 (external edit)