I\'m using Windows Vista OS. PHP, MySQL as the database and Apache web server.
I want to send notification to those who want to join in my site. But the problem is w
I would recommend using the swiftmailer library, the project has very good documentation and is easy to use. It offers several advantages to using the default PHP mail() function aswell.
http://swiftmailer.org/
Use the Pear "Mail" class, which requires access to a separate SMTP server listening on port 25.
Sample code follows:
function sendmail($from, $to, $subject, $message, $headers)
{
if (is_array($to)) {
$recipients = implode(', ', $to);
} else {
$recipients = $to;
}
$errorlevel = error_reporting();
$headers["From"] = $from;
$headers["To"] = $to;
$headers["Subject"] = $subject;
$params = array();
$params["host"] = "localhost";
$params["port"] = "25";
$params["auth"] = false;
error_reporting($errorlevel & ~E_WARNING);
$mail_object =& Mail::factory("smtp", $params);
$res = $mail_object->send($recipients, $headers, $message);
error_reporting($errorlevel);
return $res;
}
nb: this is old code - I don't recall now why I had to mask out E_WARNING
Just check out "How to Send Email from a PHP Script". It uses the mail function to send mail and it further gives configuration for local and remote SMTP configuration too.
You have several options:
It looks that you dont have a mailserver installed. Apache or PHP are not sending mails for you. Php is registering functions for that but internally you have to configure a mail smtp server to do the actual sending.
Check this post.
There are many ways to send email via PHP. Using the internal mail()
function is the first if you are not using any framework. I suggest using the Zend_Mail component of the Zend Framework. I've worked with it and it works very well and grants you a nice Object Oriented way to send emails using PHP.
But if you have your reasons to use the mail()
function, then I think you might need to know these:
PHP mail()
does not send email itself. It utilizes other tools to send emails. If you are running your application in Unix systems, mail()
tries to send the email by using the sendmail program which is commonly installed on most Unix-like systems.
On Windows platforms, there is no sendmail installed so PHP will try to send the email using an SMTP server. so you should tell PHP where this SMTP server is and provide it with the username/password of the SMTP server, if there are any.
You can do this by editing your PHP configuration file, php.ini
. This file is a text-based configuration file that PHP will use when executed.
Find your php.ini
file and modify these values in this file:
SMTP = localhost
smtp_port = 25
sendmail_from = me@example.com
If you do not know where is your php.ini
file, create a simple PHP file, like info.php
and put this code in it:
<?php
phpinfo();
?>
Run your page and search for .ini
.
Now you know where your php.ini
file is.