views:

677

answers:

6

I am using a script that is sending out emails and I am receiving the following 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\bin\php\php5.3.0\PEAR\Mail\mail.php on line 125

How to i figure out the stmp_port for my localhost?

EDIT:

I am sorry. I don't have my own server on my computer and I don't think I want to set one up either. I didn't realiza that it what it takes. I do have a hosting provider though and would like to figure out how to use their smtp information to send my mail though if anyone knows how to do that.

According to the reply by Nathan Adams, I can use my hosting provider's smtp information. What exactly do I need to find out where do I put that information in my php.ini file?

+1  A: 

You must be running an SMTP server, otherwise you need to set SMTP and smtp_port in php.ini to someone else's (your ISPs, your hosting providers ect).

Nathan Adams
I have a hosting provider. What do I need to look up and where do I need to post that in the php.ini file? Here?[mail function]; For Win32 only.; http://php.net/smtpSMTP = localhost; http://php.net/smtp-portsmtp_port = 25
zeckdude
A: 

Do you have a smtp server installed? Is it running? Not sure what platform you are on, but on windows you can run "netstat -a" from the command line and look for a status of "LISTENING"

Ted Elliott
A: 

If you don't have an SMTP server listening on port 25 then chances are you don't have a SMTP server running. Only under very customized scenarios would a SMTP server be configured to listen on a different port.

The answer to you original question is "it depends". It depends on what software you're using for SMTP (on the server side). I'm not sure there is an easy solution to see if there is "some" SMTP server running on "some" port.

ChronoFish
A: 

If you're running an SMTP server on your local host, you must have installed and configured (and it's peculiar indeed that you picked a port != 25...), so just read your configuration files to find out where you installed it to run! More likely, if you've never heard about it, you're probably not running any SMTP server and then your choice is either to do so (hint: use port 25 if you do, make your like easier!-) or find out some other SMTP server who's willing to accomodate you and set your PHP configuration to point to that one.

Edit: now that you've mentioned in a comment that you're on a hosting provider, then of course you should ask your provider what host (could be localhost, could be something else) and port (all bets are off!) they're providing SMTP service to you on.

Alex Martelli
+1  A: 

It isn't only what port you need to know. You must know what is your smtp mail server's address as well.

Base as other email configuration for SMTP. you need 4 piece of information at least:

  1. SMTP Server e.g. mail.example.com
  2. SMTP Port [25 and 110 are most common use]
  3. Username e.g. [email protected]
  4. Password

Code must looks like this.

$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => 25
    'auth' => true,
    'username' => $username,
    'password' => $password));

may be easy for you to send email via your gmail account - see here

Jirapong
Thank you for the great suggestion! I didn't even realize that is an option. I will look into that further if I cannot use my hosting provider instead.
zeckdude
A: 

There is a very good chance that your PHP script is running as an anonymous system user, i.e. 'nobody' or 'www-data'.

Many hosts restrict access to port 25 (locally) from anonymous users to prevent abuse of the mailer. You may need, instead, to connect to your actual domain and authenticate prior to sending mail.

i.e. use "mydomain.com" "25" instead of "localhost", using whatever SMTP class you like. mail() is probably going to be useless.

Double check with your host to confirm this, but I suspect it is the case.

Tim Post