22

I have spent all the morning searching this on internet trying to find a solution about this. I have installed wamp server on Windows 8.1 and i'm trying to send some mails with sendmail (http://glob.com.au/sendmail/) and my gmail account

When i configure sendmail to use port nº 465 I always get this error: Socket Error # 10060Connection timed out

If i try to use port nº 587 i get this line on error log: Connection Closed Gracefully. But no email is sent.

This is my sendmail.ini file

[sendmail]
smtp_server=smtp.gmail.com
;I tried both: 587, 465
smtp_port=587
; I tried: "blank, auto ssl, tls, none"
smtp_ssl=
error_logfile=error.log
debug_logfile=debug.log
auth_username=myaccoun@gmail.com
auth_password=mypass
hostname=localhost

And this is php.ini file

[mail function]
smtp_port = 465
sendmail_path="C:\wamp\sendmail\sendmail.exe -t"
mail.add_x_header = On

ssl_module is active on apache, and php uses php_open_ssl and php_socket extension.

Also i tried to use stunnel whitout any success

EDIT 27/01/2014

I set smtp_port = 465 and smtp_ssl=ssl on sendmail.ini. Also, I set that sendmail.exe has to run as a Windows XP SP3 programs. After doing that, when I run sendmail.exe on windows console, it sends the email correctly. However, when wamp tries to send mails i get this error on sendmail's error logs.: Socket Error # 10060Connection timed out.

This is the code I'm using to test sendmail:

<?php
$email = "mymail@gmail.com";
$to = "mymail@gmail.com";
$subject = "Hi!";
$body = "Hi,How are you?";
$headers = 'From: ' .$email . "\r\n".'Reply-To: ' . $email. "\r\n".'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $body, $headers)) echo("<p>Email successfully sent</p>");
else echo("<p>Email delivery failed</p>");
?>
AnFi
  • 10,493
  • 3
  • 23
  • 47
Rumpelstinsk
  • 3,107
  • 3
  • 30
  • 57
  • 1
    The only thing that looks wrong is `hostname=localhost` try commenting that out. – RiggsFolly Jan 25 '14 at 16:25
  • Thanks for reply. I tried it, but it didn't resolve the problem. :( – Rumpelstinsk Jan 27 '14 at 08:56
  • 1
    You could try adding this line to your `php.ini` in the '[mail function]` section. `mail.log = "c:\wamp\logs\php_mail.log"` this will turn mail logging on and may help you identify the problem. – RiggsFolly Jan 27 '14 at 09:27
  • After doing that, and do another test, this is the content of php_mail.log: mail() on [C:\wamp\www\testSendMail.php:7]: To: myemail@gmail.com -- Headers: From: myemail@gmail.com Reply-To: myemail@gmail.com X-Mailer: PHP/5.4.16. The sendmail error log only has:Connection Closed Gracefully. – Rumpelstinsk Jan 27 '14 at 11:12
  • Maybe you are not creating the email properly in your php. – RiggsFolly Jan 27 '14 at 11:39
  • Possible duplicate of [sendmail.exe opens on sending mail](http://stackoverflow.com/questions/24514432/sendmail-exe-opens-on-sending-mail) – Pascal Jan 14 '16 at 06:48

4 Answers4

68

Finally I found the answer.

The problem is that sendmail has to be run as an administrator. This is the solution to help any one on my situation.

  1. Right click on sendmail.exe
  2. Properties
  3. Compatibility
  4. Change the configuration for all users
  5. Execute as Windows XP SP 3
  6. Execute as adminitrator

And save :D

2 days lost in this nonsense :(

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
Rumpelstinsk
  • 3,107
  • 3
  • 30
  • 57
8

As an extension to the accepted answer:

If you are running the send mail function in PHP, a dialog may come up to ask you to run the 'send mail' app as admin. Upon cliking 'Yes' it will show a command prompt dialog and nothing will happen and you page will hang until the command prompt is closed. The mail function will even return "True", but in reality no message was sent.

To solve this issue, do the instructions same as the accepted answer and ALSO run the server (or IDE) as admin, by either:

1) Right clicking the program (e.g. server, ide, command prompt) and clicking "Run as Administer"

2) OR Right click program> properties> compatiblity> Tick execute as admin

For instance if your using the PHP in built server, run the command prompt as admin and start the server as normal using

C:\wamp\bin\php\php5.5.12\php.exe -S localhost:80 -t C:\Users\path\to\rootFolder

Of course change the file paths to suit your needs.

Hope this helps someone!!! Spent ages on this!

Yahya Uddin
  • 26,997
  • 35
  • 140
  • 231
  • 1
    That saved my day! Thanks – Arnie Aug 05 '15 at 13:13
  • Am using an old xampp install and as Yahya mentioned I set C:\xampp\xampp-control.exe to run as admin as well as doing what Rumppelstinsk mentioned. I stopped getting a sendmail command prompt popup and a "Socket Error # 10060Connection timed out." error in my sendmail error.log. Thanks – Carlton Aug 07 '15 at 08:03
  • Try to also set /php/php.exe to run as admin. For me this worked. – Dollique Mar 13 '16 at 13:22
7

The problem is that sendmail has to be run as an administrator. This is the solution to help any one on my situation.

  1. Right click on sendmail.exe
  2. Properties
  3. Compatibility
  4. Change the configuration for all users
  5. Execute as Windows XP SP 3
  6. Execute as adminitrator
  7. if you using gmail you need create new password "Your application-specific passwords"
Lucifer
  • 29,392
  • 25
  • 90
  • 143
1

Compatibility Troubleshooter

On Windows 10, I found the only method that worked was to run the Compatibility Troubleshooter.

  1. Right click on sendmail.exe
  2. Click "Properties"
  3. Select the Compatibility tab.
  4. Click "Run Compatibility Troubleshooter".
  5. Let windows fix it automatically.
Matt
  • 31
  • 3