tags:

views:

838

answers:

6

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 = "[email protected]";
$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>");
 }
?>
+2  A: 

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

Alnitak
A: 

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.

serioys sam
+2  A: 

You have several options:

  • there's built in mail function, but it requires that some MTA is running on the machine, doesn't support authentication, and you'll need to work hard to send attachments
  • there's Pear Mail package, if you like to use Pear stuff
  • there's a good PHPMailer class which I used in past few years and it works really great. It like it because it is very simple and easy to include in your project (just a simple include call), yet powerful
Milan Babuškov
does PHPmailer lass work in Windows Vista OS?
I tried on both Windows and Linux and it works.
Milan Babuškov
+3  A: 

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!

tharkun
A: 

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 = [email protected]

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.

farzad
A: 

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.

Elzo Valugi