Thursday, August 22, 2013

Sending emails from PHP through Exchange using NTLM authentication

My colleague in Russia had a problem to send emails form PHP. Main reason was, that PHP does not support authentication on SMTP connection. Second problem was, that smtp is Microsoft Exchange, which require NTLM authentication using active directory user. Solution I have found is described in this post.

Get sendmail

Download and extract Fake sendmail (http://glob.com.au/sendmail/).
I have chosen path c:\sendmail

Configure sendmail

Configure sendmail by editing sendmail.ini. Simply add exchange address and user credentials (Don't forget to limit read permissions):

smtp_server=exchange_server_name
auth_username=domain_user (full format: DOMAIN\user)
auth_password=pass

Configure PHP 

Configure PHP by editing php.ini file:

[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 = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "c:\sendmail\sendmail.exe -t"

Test it

Thats all. Now PHP sends emails through local sendmail and exchage server. You can test it using script like:

<?php
mail('recipient@example.com', 'subject', 'message', 'From: sender@example.com');

1 comment:

  1. Mardi Gras Casino & Racetrack - Mapyro
    Results 1 - 25 of 3831 — Mardi Gras 성남 출장안마 Casino & Racetrack - 진주 출장마사지 Las Vegas, NV 89109. 사천 출장안마 Find directions, reviews and 안산 출장안마 information for 양주 출장샵 Mardi Gras Casino & Racetrack in Las Vegas,

    ReplyDelete