10

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?

9
  • Are you running IIS or Apache... maybe this would be useful, neatcomponents.com/enable-SMTP-in-Windows-8
    – chris85
    Commented Jun 3, 2015 at 3:34
  • are you running a mailserver? im guessing no
    – user557846
    Commented Jun 3, 2015 at 3:38
  • @chris85, I think, Wamp server uses apache. No mail server.
    – cola
    Commented Jun 3, 2015 at 3:40
  • well to send email you need one, but from wamp mot people use another, such as your ISP's or gmail. if you ever plan to host this it may be better to jump that step now and use your web hosts mail server. stackoverflow.com/questions/3412055/…
    – user557846
    Commented Jun 3, 2015 at 3:42
  • @Dagon, Which mail server to install?
    – cola
    Commented Jun 3, 2015 at 3:48

8 Answers 8

11

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

3
  • @shibly read this to. stackoverflow.com/questions/30702003/… Commented Jun 16, 2015 at 7:30
  • 1
    It's working after changing the compatibility mode of sendmail.exe from properties. For windows 7 or above, you have to change the compatibility mode of sendmail.exe to "Windows xp service pack 3" from properties. stackoverflow.com/questions/21337859/sendmail-wamp-php , see "issues running on windows 8+" here in glob.com.au/sendmail
    – cola
    Commented Mar 8, 2016 at 15:04
  • Use the latest sendmail for Windows and follow the basic installation instructions, make sure to remove the smtp configuration from your php.ini file because that isn't really required if you already handle those values in your sendmail.ini file. Also I was only able to get it to work if I use sendmail_path = "C:\Program Files (x86)\sendmail\sendmail.exe" without the -t parameter. If anyone is curious, I was using IIS on Windows 10.
    – haZh
    Commented Oct 17, 2020 at 13:51
5
+50

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.

2
  • If you drop the first line, you have IMHO the only correct answer, which is: don't use PHP's mail() function. Commented Jun 10, 2015 at 19:23
  • @JasperN.Brouwer Yes, same here. Do not think using the mail() function is a good idea. But included that link if somehow the questioner could get some ideas from there.
    – chanafdo
    Commented Jun 11, 2015 at 5:50
1

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. ;)

1

I'd recommend mercury (http://www.pmail.com/downloads_s3_t.htm - Mercury/32 Mail Transport System for Win32 and NetWare Systems v4.74).

This is included in XAMPP, fairly easy to set up and you don't need to configure or (ab)use an email account. You can see the whole smtp transaction in mercury mail log window.

1

Look here for an excellent answer on how to setup mailing from php: PHP mail form doesn't complete sending e-mail

1

Use this function tool: https://github.com/PHPMailer/PHPMailer

Mail() is prette dificult to use and this function allows you to use the email servers STMP function to send emails.

Read documentation here: https://github.com/PHPMailer/PHPMailer/blob/master/README.md

1

You need to use email server along with php. https://www.hmailserver.com/

0

When you are using an e-mail sender functionality through a server that requires SMTP Authentication, you must need to specify it. And set the host, username and password (and maybe the port if it is not the default one - 25).

For example, I usually use PHPMailer with similar settings to this ones:

//ini settings
ini_set("SMTP", "aspmx.l.google.com");
ini_set("sendmail_from", "[email protected]");

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';

$mail->Host       = "mail.example.com"; // SMTP server example
$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "username"; //Your SMTP account username example
$mail->Password   = "password";        //Your SMTP account password example

You can find more about PHPMailer here.

You can video ride for how SMTP configure on wondows here.

Not the answer you're looking for? Browse other questions tagged or ask your own question.