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 when I click submit. It doesn't send anything to the email address of the user.
What to do you think is the best solution for this?
<?php
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
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 themail()
function, then I think you might need to know these: PHPmail()
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 yourphp.ini
file and modify these values in this file:If you do not know where is your
php.ini
file, create a simple PHP file, likeinfo.php
and put this code in it:Run your page and search for
.ini
. Now you know where yourphp.ini
file is.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.
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:
Zend_Mail of the Zend Framework does a very neat job with sending E-Mails!! You don't need to use the whole of Zend Framework, you can just use Zend_Mail!
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/