PHP has mail() function to send an email to users. However this mail() will not work:
=> If sendmail (or compatible binary) is not installed
=> If Apache Web server / Lighttpd running in chrooted jail
=> And your smtp server needs an authentication before sending an email
=> Or you just need to send email using PHP PEAR
In all these cases you need to use PHP PEAR’s Mail:: interface. It defines the interface for implementing mailers under the PEAR hierarchy, and provides supporting functions which are useful in multiple mailer backends. In this tip you will learn about how to send an e-mail directly to client smtp server in real time.
PHP Pear’s Mail.php is located in /usr/share/pear/ directory. Following is sample code to send an email via authenticated smtp server.
PHP send email using PHP SMTP mail Pear functions – Sample source code
Following code is well commented, you need to make necessary changes as per your setup.
<?php include("Mail.php"); /* mail setup recipients, subject etc */ $recipients = "feedback@yourdot.com"; $headers["From"] = "user@somewhere.com"; $headers["To"] = "feedback@yourdot.com"; $headers["Subject"] = "User feedback"; $mailmsg = "Hello, This is a test."; /* SMTP server name, port, user/passwd */ $smtpinfo["host"] = "smtp.mycorp.com"; $smtpinfo["port"] = "25"; $smtpinfo["auth"] = true; $smtpinfo["username"] = "smtpusername"; $smtpinfo["password"] = "smtpPassword"; /* Create the mail object using the Mail::factory method */ $mail_object =& Mail::factory("smtp", $smtpinfo); /* Ok send mail */ $mail_object->send($recipients, $headers, $mailmsg); ?>
Filed under: PHP, Web Application | Tagged: PHP Developer in Bhubaneswar

What should I do to be able to send HTML in my $mailmsg?
As it is now, it don’t accept HTML and the message get sent with the HTML tags