Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't send email with php mail function on windows 8

I have installed wamp on windows 8.

Got error:

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\mail.php on line 9

Here is the simple source code:

<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");

// Send
mail('[email protected]', 'My Subject', $message);
?>

Which software do i have to install to email through php on windows 8? sendmail, msmtp or ssmtp?

like image 421
shibly Avatar asked Jun 03 '15 03:06

shibly


3 Answers

Try this

image

Configure This Setups

in php.ini

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = [email protected]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

in sendmail.ini:

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=my-gmail-password
[email protected]

Important: comment following line if there is another sendmail_path in the php.ini : sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

Note: Tested and works fine in my Windows 8.1

like image 151
Abdulla Nilam Avatar answered Sep 19 '22 15:09

Abdulla Nilam


Possible solution. See this question

For me configuring a mail client on localhost is quite difficult. I also tried quite a few times. Later I moved on to other solutions.

You can use SwiftMailer or PhpMailer with some configuration or you can try this tool with zero configuration.

like image 37
chanafdo Avatar answered Sep 20 '22 15:09

chanafdo


On a side note, if you are using your windows PC for development and not as a production server, then I suggest that you don't bother setting up a sendmail in windows, just use this handy tool.

Test Mail Server Tool (Its Free)

It will emulate an email server and once any script tries to send an email, it will intercept it and open it for you as an .eml file, which you can open up in any email reader like outlook or mail viewer(again its free).

Now setting this tool up is just a breez, and you will thank me later for all the time that you saved, from not having to manually setup the sendmail, which I must mention is meant to be on a linux machine. ;)

like image 45
Mohd Abdul Mujib Avatar answered Sep 17 '22 15:09

Mohd Abdul Mujib