Problem
How do I set up outbound SMTP using PEAR::Mail?
Solution
The following example of code shows you how to send an email using outMail as the SMTP SmartHost mail relay using the PEAR::Mail module for php.
outMail is an authenticated SMTP relay so the example below shows authentication in php as well. The code below uses the default SMTP port 25 but it can easily be changed to an alternative SMTP port by editing the line code $mail_params['port'].
Example code smtp-test.php
<html>
<head>
<title>SMTP Test using PEAR::Mail in PHP</title>
</head>
<body>
<?php
require_once('Mail.php');
// set the recipients (to) address [REQUIRED]
$mail_to = 'recipient@example.com';
// set the mail headers which include sender address, subject, etc
$mail_headers['From'] = 'me@example.com';
$mail_headers['To'] = $mail_to;
$mail_headers['Subject'] = 'Test message';
// set the mail content
$mail_body = "The test messsage is having this body line inside.";
// set the smtp mail server [REQUIRED]
$mail_params['host'] = 'mxXXXXXX.smtp-engine.com';
$mail_params['port'] = 25; // Can use alternative ports if needed (See below)
$mail_params['auth'] = 'PLAIN';
$mail_params['username'] = 'outmail-username';
$mail_params['password'] = 'outmail-password';
// optional SMTP debug options
// $mail_params['debug'] = true;
// Create the mail object using Mail::factory
$mail_object =& Mail::factory('smtp', $mail_params);
// Send the message
$mail_object->send($mail_to, $mail_headers, $mail_body);
?>
</body>
</html>
Summary of server details
Outgoing server |
mxXXXXXX.smtp-engine.com As provided in your signup email. |
Outgoing server protocol |
SMTP |
Outgoing server port |
25, 465, 587, 2525 or 8025 |
Authentication Type |
Basic Authentication, SSL and TLS supported |
Username |
As provided |
Password |
As provided |
Looking for an outgoing #SMTP server?
outMail is an outbound #SMTP Server.
- Supports SMTP & API protocols for sending emails.
- Support for SMTP ports and alternative ports.
- Authenticated SMTP
- Support for SPF & DKIM
- Easy setup