Showing posts with label Gmail. Show all posts
Showing posts with label Gmail. Show all posts

Wednesday, 15 April 2009

Solving: "Must issue a STARTTLS command first" for PHP's mail function (using Google's SMTP Server)

My ISP previously provided their own SMTP Server. The PHP configuration for sending e-mails was then relatively simple (php.ini file):

[mail function]
; For Win32 only.
SMTP = smtp.freesurf.ch
smtp_port = 25

; For Win32 only.
sendmail_from = <e-mail username>@freesurf.ch

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"

Unfortunately my ISP switched their e-mail accounts to Google's Gmail. I tried to use a similar configuration:

[mail function]
; For Win32 only.
SMTP = smtp.gmail.com
smtp_port = 25

; For Win32 only.
sendmail_from = <e-mail username>@gmail.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"

The problem was that I kept getting the following message from Google's SMTP Server:
"530 5.7.0 Must issue a STARTTLS command first."

The reason for this is that gmail uses secure (TLS) servers to prevent spam.

There are several ways to resolve this problem (one way is by installing a SMTP server on your localhost) but here is the easiest way I found:

As I was using XAMPP I had already installed the "fake sendmail for windows". If you are not using XAMPP you can download it here:
http://glob.com.au/sendmail/sendmail.zip

I then modified the php.ini file to use it (commented out the other lines):

[mail function]
; For Win32 only.
; SMTP = smtp.gmail.com
; smtp_port = 25

; For Win32 only.
; sendmail_from = <e-mail username>@gmail.com

; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"

Ignore the "For Unix only" comment, as this version of sendmail works for Windows.

You then have to configure the "sendmail.ini" file in the directory where sendmail was installed:

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=<username>
auth_password=<password>
force_sender=<e-mail username>@gmail.com


The configuration is nearly over but not completely, you will still get the message: "Must issue a STARTTLS command first".

To solve this problem you need to download the following zip file:
http://glob.com.au/sendmail/sendmail-SSL.zip
and install its contents in the sendmail directory. That will make sendmail.exe TLS compatible.

That's it. I hope this will be useful to some people.

Please bookmark, your votes are noticed and appreciated:
Bookmark and Share