tags:

views:

350

answers:

5

I use the latest WAMP and i get this when i try to send emails:

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\main\createaccount.php on line 8

Message delivery failed...

the message

$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }

Do you need do download a "mailserver" also?

Please help.

Thanks

+1  A: 

You are not running an smtp server on your machine, but you don't have to. Just set SMTP to a open smtp server for example:

ini_set('SMTP', 'smtp.yourisp.com');

Take a look at your ISP's home page or http://www.e-eeasy.com/SMTPServerList.aspx for list of SMTP servers.

If you have a desktop mail program, you can use the same address as you use for outgoing mail.

Tatu Ulmanen
thanksman, tried many server not but i get the same error message, maybe some other program i run use port 25 ;/
Jorm
Are sure you are putting the `ini_set` before the `mail` function and have you tried your own ISP's SMTP server?
Tatu Ulmanen
A: 

I think your mail server (SMTP) outgoing mail server is not configured in your php.ini file.

Have a look at this:

http://email.about.com/od/emailprogrammingtips/qt/Configure_PHP_to_Use_a_Remote_SMTP_Server_for_Sending_Mail.htm

Also hotmail doesn't allow you to use their mailservers. You should use yahoo or gmail.

Tony
At least Gmail requires SSL protected connection, so that's not an option with plain old `mail()`.
Tatu Ulmanen
@Tatu Ulmanen: Thanks :) I don't think yahoo does, from what I recall.
Tony
A: 

This is all i have in the script:

ini_set('SMTP', 'relay.skynet.be');

mail('[email protected]', 'Testing!', 'im just testing if it works');

tried bunch of servers but i get same message

A: 

Are you sure these servers have a mail program installed on them? If not, that's your problem. For example, XAMPP comes with a mail program called Mercury which you must start before you can send mail through the server.

John
+1  A: 

This works for me and should work for you: Use Fake Sendmail and a webhost mail server (i.e. - Godaddy, 1and1, etc.).

1.) Download the sendmail zip and extract it to C:\Wamp\bin\sendmail (for purposes of this example).

2.) Edit C:\wamp\bin\sendmail\sendmail.ini and set the following to your mail server's requirements (mine are below):

smtp_server=mail.yourdomain.com
smtp_port=26
smtp_ssl=none
;default_domain=yourdomain.com
[email protected]
auth_password=smtppassword
;pop3_server=
;pop3_username=
;pop3_password=
;force_sender=
;force_recipient=

3.) Set the path of sendmail.exe in your php.ini file.

[mail function]
; For Win32 only.
SMTP =

; For Win32 only.
sendmail_from =

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

4.) Restart Wampserver.

You might have success using Gmail, but there are a few extra tweaks to make it work. I prefer using the mail server of the webhost where I upload my code.

Josh
Exactly what I needed to link my dev. environment with the actual GoDaddy account. Much appreciated !
FreekOne