Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jan 2012
    Location
    Sweden
    Posts
    32
    Thanks
    7
    Thanked 0 Times in 0 Posts

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

    Hello,

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

    PHP 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 :)

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    What SMTP have you configured to run? The default is to look for the smtp on localhost:25.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,304
    Thanks
    57
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    New Coder
    Join Date
    Jan 2012
    Location
    Sweden
    Posts
    32
    Thanks
    7
    Thanked 0 Times in 0 Posts
    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?

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by webjoker View Post
    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.

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by webjoker View Post
    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 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 or PHPMailer that will connect to your SMTP account and send the email directly without relying on the PHP mail settings.

  • #7
    New to the CF scene
    Join Date
    Jan 2012
    Location
    Belgrade, Serbia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your code if fine , you just simply don't have the SMTP server installed on your localhost.
    Go with the links the guys have provided


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •