We all know that PHP is great for back-end development. However, some functions can be tricky to fine tune for the best web development possible. The mail() function has a high probability of sending mail to user’s “junk” or spam folders because the connection was not authenticated. To avoid that, use the following function below. This assumes you have PEAR setup and working properly.
-
-
<?php
-
require_once "Mail.php";
-
-
$from = "Sandra Sender <sender@example.com>"; $to = "Ramona Recipient <recipient@example.com>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?";
-
-
$host = "mail.example.com";
-
$username = "smtp_username";
-
$password = "smtp_password";
-
-
‘To’ => $to,
-
‘Subject’ => $subject);
-
‘auth’ => true,
-
‘username’ => $username,
-
‘password’ => $password));
-
-
$mail = $smtp->send($to, $headers, $body);
-
-
if (PEAR::isError($mail)) {
-
} else {
-
}
-
?>
-
-






