Due to the security purpose, almost all hosting provider stopped the default smtp server. Default smtp server can be misused by sending spam mail that will leads to IP block in various spam dbs. Still if you are trying to use default mail function you may get the following error.
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Sending mail through php with SMTP authentication.
Before writing the code you have to create one email id, so that you can use that email id and its password in the code. Always use the email id under the same domain. So that you can use the same hosting provider email server to send mails.
require_once "Mail.php";
$from =
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
;
$to = "reciever email id";
$subject = "this is the message from your domain";
$body = "give your message body here";
$host = "mail.yourdomain.com";
$username =
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
;
$password = "mypassword";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("
" . $mail->getMessage() . "
");} else {
echo("
Thank you.
Please Visit Again!
}
?>
Note
This e-mail address is being protected from spambots. You need JavaScript enabled to view it has to be replaced by your mail id
receiver email id has to be replaced by receiver mail id
mail.yourdomain.com has to be replaced by real smtp server (eg : mail.asklijo.com)
mypassword has to be replaced by your emailid’s password.
You will get the clear cut idea to use the mail function with smtp authentication. If you use this method no chance of moving your mail to spam or junk folder


