5 Replies - 904 Views - Last Post: 04 June 2011 - 11:04 PM Rate Topic: -----

#1 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

How do you actually use mail()?

Posted 04 June 2011 - 10:08 PM

I'm not sure I quite understand how this works, because no matter what I do I get an error when it tries to send an email.

The only code I have is this:
$to      = 'otlzack@yahoo.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: otlzack@yahoo.com' . "\r\n" .
    'Reply-To: otlzack@yahoo.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);



That came straight from the php manual.

Now I must be missing something because this error occurs:
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:\Program Files\Apache Software Foundation\Apache2.2\htdocs\profile.php on line 13

So I check my php.ini:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com

Is this good? I honestly have no idea.

What more is needed? Does the mail function actually work this way? The otlzack@yahoo.com is just some random yahoo account I've had for years, does the email address need to somehow be affiliated with my server? If so, how?

And I'm not even sure about the smtp_port = 25 part. Do I have to manually set the smtp_port on my computer to use 25? If so, how do you do that? I know next to nothing about that kind of stuff.

Hopefully somebody can clear this up for me. I'm just really confused as to how this function actually works and I'd love to get it working for a Forgot Password page I'd like to implement.

Not sure if it's relevant, but my OS is Windows.


Thanks!

This post has been edited by eZACKe: 04 June 2011 - 10:09 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How do you actually use mail()?

#2 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: How do you actually use mail()?

Posted 04 June 2011 - 10:14 PM

There isn't a mail server on your local machine that's actually needed to send the mail. SMTP runs on port 25 and PHP is trying to connect to a mail server through that port.

Check out hMailServer.
Was This Post Helpful? 2
  • +
  • -

#3 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: How do you actually use mail()?

Posted 04 June 2011 - 10:19 PM

Ok cool. So I download this, then when SMTP runs it should find this server and be able to send the email?

Am I understanding this correctly?
Was This Post Helpful? 0
  • +
  • -

#4 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: How do you actually use mail()?

Posted 04 June 2011 - 10:21 PM

If you configure it correctly then yes.
Was This Post Helpful? 0
  • +
  • -

#5 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: How do you actually use mail()?

Posted 04 June 2011 - 10:23 PM

View Postcodeprada, on 05 June 2011 - 03:21 AM, said:

If you configure it correctly then yes.



Ok thanks, though unlikely that I will configure it correctly...at least at first.

EDIT: Hmmm, will you look at that it actually worked.

I have a question though. When I first tried it I got this error:
SMTP server response: 530 SMTP authentication is required

I then went to Advance, IP Ranges and looked at the Require SMTP Authentication section. The box External to external email-address was the only one checked so I unchecked it. It then worked. My question is, should I be concerned that none of these boxes are checked? Does it matter?

This post has been edited by eZACKe: 04 June 2011 - 10:30 PM

Was This Post Helpful? 0
  • +
  • -

#6 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 946
  • View blog
  • Posts: 2,355
  • Joined: 15-February 11

Re: How do you actually use mail()?

Posted 04 June 2011 - 11:04 PM

The documentation answers it

hMailServer Doc said:

530 SMTP authentication is required.
You have enabled SMTP authentication for the IP range that the user is connecting from, but the user has not configured his client to use SMTP authentication. There's two ways to solve this problem. Either configure your email client to use SMTP authentication. This setting is normally found in the account settings in your email client. Or, disable SMTP authentication for the IP range. The first solution is recommended since it reduces the risk that anyone will send spam through your server.

By default, hMailServer does not require SMTP authentication for connections coming from localhost / 127.0.0.1. For connections coming from other hosts, SMTP authentication is required for deliveries to external recipients. By default, hMailServer never requires SMTP authentication for deliveries to local accounts, since that would prevent other e-mail servers to deliver email to your installation. For information on how to enable SMTP authentication, check the HOWTO.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1