I’m trying to send an email with the following function as a test function:
function SendEmail($to, $subject, $body, $headers)
{
ini_set("SMTP", "smtp.myexistingdomain.com");
mail($to, $subject, $body, $headers);
}
and I get this error:
Warning: mail() [function.mail]: Failed to connect to mailserver at
“smtp.myexistingdomain.com” port 25, verify your “SMTP” and
“smtp_port” setting in php.ini or use ini_set()
PHP doesn’t implement SMTP protocol. PHP’s mail() – is wrapping around sendmail binary. Works fine on unix/linux.
But On Windows (from PHP.net manual):
So – the moral of the story – you need to install mail server.
If you prefer to send emails without installing you own mailserver (which can be a pain in the *ss) – you must use a library that actually implements SMTP protocol and thus allows you to connect to someone else SMTP server.
These are most popular nowadays:
Using these libraries one can construct text or html messages with ease. Adding files also becomes an easy thing to do.