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('caffeinated@example.com', 'My Subject', $message);
?>

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

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
cola
  • 12,198
  • 36
  • 105
  • 165
  • Are you running IIS or Apache... maybe this would be useful, http://www.neatcomponents.com/enable-SMTP-in-Windows-8 – chris85 Jun 03 '15 at 03:34
  • are you running a mailserver? im guessing no –  Jun 03 '15 at 03:38
  • @chris85, I think, Wamp server uses apache. No mail server. – cola Jun 03 '15 at 03: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. http://stackoverflow.com/questions/3412055/why-mail-php-function-does-not-work-with-wamp-default-installation?rq=1 –  Jun 03 '15 at 03:42
  • @Dagon, Which mail server to install? – cola Jun 03 '15 at 03:48
  • - you dont, use your ISP\gmail or move this to a hosted site setting up your own mail server is not really an option –  Jun 03 '15 at 03:50
  • Solution is right here http://stackoverflow.com/questions/21337859/sendmail-wamp-php Run sendmail as administrator. – venca Jun 08 '15 at 12:51
  • Check whether the port 25 is open or not. Add exception in all the firewalls you have – Kirs Sudh Jun 14 '15 at 07:26
  • Is your mail funtion working?? Or stil out with errors?? – Abdulla Nilam Jun 17 '15 at 14:44

8 Answers8

11

Try this

image

Configure This Setups

in php.ini

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
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
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com

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

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
  • @shibly read this to. http://stackoverflow.com/questions/30702003/how-to-send-email-from-localhost-using-codeigniter/30703350#30703350 – Abdulla Nilam Jun 16 '15 at 07: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. http://stackoverflow.com/questions/21337859/sendmail-wamp-php , see "issues running on windows 8+" here in http://glob.com.au/sendmail/ – cola Mar 08 '16 at 15:04
  • Use the latest [sendmail for Windows](https://github.com/sendmail-tls1-2/main) 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 Oct 17 '20 at 13:51
5

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.

Community
  • 1
  • 1
chanafdo
  • 5,016
  • 3
  • 29
  • 46
  • If you drop the first line, you have IMHO the only correct answer, which is: _don't_ use PHP's `mail()` function. – Jasper N. Brouwer Jun 10 '15 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 Jun 11 '15 at 05: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. ;)

Mohd Abdul Mujib
  • 13,071
  • 8
  • 64
  • 88
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.

mgrueter
  • 1,400
  • 6
  • 15
1

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

Community
  • 1
  • 1
robinp7720
  • 443
  • 4
  • 12
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

HereToHelpPHP
  • 189
  • 11
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", "YOURMAIL@gmail.com");

$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.

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57