Jump to content

Unable to send e-mail from localhost

- - - - -

  • Please log in to reply
5 replies to this topic

#1
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Hi. I use this code to send e-mail to all users that are registered in database:

<?php
    $emailName = mysql_real_escape_string($_POST['emailName']);
    $letter = mysql_real_escape_string($_POST['letterText']);

    $con = mysql_connect("localhost", "root", "");
    
    if (!$con){
        die('Could not connect: ' . mysql_error());
    } 
    
    mysql_select_db("History", $con);
    
    $result = mysql_query("SELECT * FROM NewsletterSubscribers");
    while ($row = mysql_fetch_array($result)){
        $to = $row['Email'];
        mail($to, $emailName, $letter);
    }
    
    mysql_close($con);
?>
However, i get such 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\MH2\sendEmail.php on line 16

Any tips how to solve that problem?



#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Do you have a mail server running on localhost?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
I dont't know. I use wamp 2.1

#4
Revolt

Revolt

    Programmer

  • Members
  • PipPipPip
  • 99 posts
I don't think wamp pre-configures an email account so you either do that or you can use the Mail PEAR package to send a mail using gmail for example:

Send email using GMail SMTP server from PHP page - Stack Overflow

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Hello thatsme,

Normally the script would connect with an SMTP mail server, and that server will send the email out to the client. If you are on your local home machine, your ISP likely has an SMTP server available for you to use (usually from yourname@yourisp.com) and this can be configured either in php.ini or a PHP mail package such as PEAR::mail or PHPMailer.

Most shared web hosts come preconfigured with an SMTP server available for clients to use, so if you could do your actual mail testing on there rather than localhost it may benefit you from having to either set up or find a service to send mail from as well.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
For doing testing on Windows, I use this tool: http://www.toolheap....il-server-tool/
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users