Knowledgebase: outmail
How do I set up outbound SMTP using PEAR::Mail?

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, 587, 2525 or 8025

Authentication Type

Basic Authentication

Username

As provided

Password

As provided

 

(0 vote(s))
Helpful
Not helpful





Disclaimer
The Origin of this information may be internal or external to Prolateral Consulting Ltd. Prolateral makes all reasonable efforts to verify this information. However, the information provided in this document is for your information only. Prolateral makes no explicit or implied claims to the validity of this information. Any trademarks referenced in this document are the property of their respective owners.