Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
529 views
in Technique[技术] by (71.8m points)

email - Why mail() PHP function does not work with WAMP default installation?

I have a default installation of WAMP Server 2.0.

I'm trying to send email using this simple script:

<?php

if (mail('[email protected]', 'My Title', 'Some Text')) {
    echo "OK";
} else {
    echo "Why ??";
}

?>

Unfortunately, I get the following warning:

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:My_Pathsend_email.php on line 3 Why ??

What could be the reason for that ?

I expected sending email to be a very simple task ... :(

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To be able to send email you need an outgoing email server (MTA). In most Linux systems there exists one by default, and PHP will use it by submitting mail to sendmail, a Linux app/alias for submitting mail to whichever MTA you have installed.

Windows doesn't include an MTA by default. In Windows, to be able to send mail from PHP you need to have access to some outgoing email server and tell PHP the address and port of it. This is done in php.ini using the SMTP and smtp_port settings. It will default to localhost on port 25. Unless you have set up a mail server on that machine yourself, this will fail.

If your ISP gives you an outgoing mail server, for example, you could use its address and port number. Or, if you're serious about sending mail, you'd set up your own mail server on the local machine or somewhere in your local network.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...