$mailer->IsMAIL();
tells PHPMailer
to use the PHP mail()
function for emails delivery. It works out of the box on Unix-like OSes but not on Windows because the desktop versions of Windows do not install a SMTP server (it is available on the installation disc).
In order to make it work on Windows you have to change the PHP configuration. Either you edit php.ini
(the configuration will apply globally) or you can use function ini_set()
to change it only for current execution of the current script.
The best way is to change php.ini
. You can find it in the PHP's installation directory or in the Windows's directory. Check the output of PHP function phpinfo()
to find out its exact location.
Open php.ini
in a text editor (the one you use to write the code is the best) and search for a section that looks like this:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = [email protected]
For SMTP
, use the name or the IP address of your company's mail server. Or your ISP's mail server if you are at home. Or check the configuration of your email client.
The smtp_port
is either 25
for standard SMTP
or 587
if the server uses SSL
to encrypt its communication.
Also uncomment the sendmail_from
setting if it is commented out (remove the ;
from the beginning of line) and put your email address there.
Read more about the PHP configuration for sending emails on Windows on the documentation page.
Another option is to install a SMTP server on the computer. You can find one on the Windows installation disc or you can use a third-party solution.
If you choose to not install a SMTP server on the computer you don't even need to modify php.ini
. You can change the code of the script to use a SMTP server:
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = "mail.example.com";
$mailer->Port = 25;
Check this PHPmailer example for all the settings and their meaning.
If the SMTP server uses SMTP authentication (the webmail providers do it, your ISP or your company might do it or might not do it) then you have to also add:
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "yourpassword";
If you use Gmail's SMTP server, for example, then use your Gmail email address and password. Replace "Gmail" with "Hotmail" or "Yahoo!" or your webmail provider or your company in the sentence above.