...

View Full Version : Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port



webjoker
01-18-2012, 04:43 PM
Hello,

what i am trying to do is too send an email at my localhost adress.
This is my code:



<?php
$to = "somebody@mail.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: somebodyelse@mail.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to,$subject,$txt,$headers);
?>

But when i am trying to do that all it says is "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port " Well... here is my question then, does someone know what i am doing wrong? :)

Would really love some help because i hope to get this mail stuff work as soon as possible!

Regards: Webjoker :)

Fou-Lu
01-18-2012, 06:10 PM
What SMTP have you configured to run? The default is to look for the smtp on localhost:25.

tangoforce
01-18-2012, 06:46 PM
IF you don't have a SMTP server, then google 'fakesendmail' and install that. It works in a similar way to the linux version of sendmail.

webjoker
01-18-2012, 07:33 PM
sorry,but i am not really used to work with PhP. Then my question is, how do i get a SMTP-server? And what excatly are a SMTP-server?

Fou-Lu
01-18-2012, 08:45 PM
sorry,but i am not really used to work with PhP. Then my question is, how do i get a SMTP-server? And what excatly are a SMTP-server?

PHP has nothing to do with a SMTP server.
Follow tango's advice and seek a free SMTP server to test with on google. Or get Linux of course.

Inigoesdr
01-18-2012, 10:11 PM
sorry,but i am not really used to work with PhP. Then my question is, how do i get a SMTP-server? And what excatly are a SMTP-server?

The error you are getting is because your PHP install has invalid mail settings (http://php.net/mail.configuration) configured. If you are on shared hosting you should contact your host about it. If not, you need to setup an SMTP account to send mail from, and update your settings to match. You can use a third-party for this(like GMail), or install an SMTP client such as sendmail/fakesendmail to send mail through. Another option is to use a PHP-based mail client such as SwiftMailer (http://swiftmailer.org/) or PHPMailer (http://phpmailer.worxware.com/) that will connect to your SMTP account and send the email directly without relying on the PHP mail settings.

karlos81
01-21-2012, 08:38 AM
Your code if fine :thumbsup: , you just simply don't have the SMTP server installed on your localhost.
Go with the links the guys have provided :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum