The below script may be useful to test the mail delivery using email authentication with and without SSL
Note:
The script uses pear Mail function, so make sure that PEAR Mail function is installed on your server.
Don’t forget to change the fields as needed …
With SSL:
<?php require_once "Mail.php"; $from = "Sender <[email protected]>"; $to = "Recipient <[email protected]>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $host = "ssl://mail.remotehost.com"; $port = "465"; $username = "[email protected]"; $password = "PASSWORD"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?>
Without SSL:
<?php require_once "Mail.php"; $from = "Sender <[email protected]>"; $to = "Recipient <[email protected]>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $host = "mail.remotehost.com"; $port = "25"; $username = "[email protected]"; $password = "PASSWORD"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?>