Simple PEAR PHP script to send emails using AuthSMTP


require_once "Mail.php";
function send_mail_pear (){
$mail_to = 'recipient1@domain.com, recipient2@domain.com';
$mail_subject = 'Enquiry From Website';
$mail_from = 'My Website '; // make sure email is authorised in your AuthSMTP account
$mail_body = 'Email body HTML';

$headers = array(
'From' => $mail_from,
'To' => $mail_to,
'Subject' => $mail_subject,
'Content-type' => 'text/html; charset=utf-8');

$smtp = Mail::factory('smtp', array(
'host' => 'ssl://mail.authsmtp.com',
'port' => '465',
'auth' => true,
'debug' => false,
'username' => 'accountId', // Your AuthSMTP account username
'password' => 'Password' // Your AuthSMTP account password
));

$mail = $smtp->send($mail_to, $headers, $mail_body);
if (PEAR::isError($mail)) { //Email sending failed (to troubleshoot set 'debug' => true)
return (false);
}
else{ // Email was sent successfully
return (true);
}
}

 

 

January 2017


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *