Primary links
Sending mail using SMTP authentication
admin — Thu, 25/03/2010 - 10:09am
Spammers are very active now a days and they are constantly searching for vulnerable scripts or servers to send spam emails. One common vulnerability in servers is where mails can be send as nobody user. Nowadays most server administrators block this and mails are allowed to be send as a valid user created in the server. When we use the mail() function in php to send emails, the emails get send as the user nobody. So this won;t work in all servers. You won't get any error in the script. Recipients won't get the emails. The if(mail(***,***,***)) will return false in such cases.
One good method to overcome this is to use SMTP authentication mode in the mailer script. The following script uses PEAR class for sending emails.
<?php
require_once "Mail.php";
$from = "You
$to = "The Recipient
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "yoursmtpserver.com";
$username = "youremailusername";
$password = "yourpassword";
$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("
Message successfully sent!
");
}
?>
User login
Follow Us
Who's online
Who's new
- Nisha
- linnaeus
- Yameen
- TalleyReedy
- admin

