Sample code for PHP SMTP authentication used script code

<?php
require_once "Mail.php";
$from = "youremail@yourdomain.com"; //replace it with full email id created on your web hosting ac hosted with us.
$to = "destination@yourdomain.com"; //replace it with email address where you want to send the email to.
$subject = " Subject Line Here: ";
$body = " any message you want ";
$host = "mail.yourdomain.com";
$port = "587";
$username = "youremail@yourdomain.com";
$password = "xxxxxxxxxxx";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'socket_options' => array('ssl' => array('verify_peer_name' => false, 'allow_self_signed' => 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>");
}
?>
Was this article helpful?
Cancel
Thank you!