Sending email without authentication
The correct way of sending email is through a SMTP connection.
Assuming the PEAR Mail package is installed.
";
$to = "Name Whatever ";
$subject = "Subject!";
$body = "Hi,\n\nHow are you?";
$host = "mail.yourdomain.com";
$username = "smtp_username";
$password = "smtp_password";
$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!
");
}
?>
Assuming you have Zend Framework, you can do the same by sending through Zend_Mail over SMTP. The example below uses information on Google SMTP
require_once 'Zend/Loader/Autoloader.php'; //Should be in the include_path
$autoloader = Zend_Loader_Autoloader::getInstance();
$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'username@gmail.com', 'password' => 'password');
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
$mail = new Zend_Mail();
if (strtolower($this->getType()) == 'html')
$mail->setBodyHtml($this->getBody());
}
else {
$mail->setBodyText($this->getBody());
}
$mail
->setFrom($this->getFromEmail(), $this->getFromName())
->addTo($this->getToEmail(), $this->getToName())
->setSubject($this->getSubject());
$mail->send($transport);