Sending via Pear SMTP instead of the standard mail()

This is a change in Dolphin 7.0.5 / 7.0.6, the only versions I have been working on.

Status: 'It works for me', please comment if you encounter any problems.

It depends on Pear Mail function so you should make a temporary php file and simple check that the server have Pear Mail installed.

An easy way to check this is to create a empty php file with the content of:

<?php
include 'Mail.php';
include 'Mail/mime.php';
?>

Save it and run it from your webbrowser to see that you dont get any problems including the files

Start by making a copy of inc/utils.inc.php so you have the original file if something bad happends.

Edit the file and look for: 'function sendMail'

After the line 'global $site;'

Add the following code (notice the include_once)

// Added custom
include_once 'Mail.php';
include_once 'Mail/mime.php';

After the code line '$sMailHeader = ...' insert the following code:

// Code added for smth auth.
$from = "email@yourdomain.com; // Add the email address you plan to use for smtp auth and from address
$smtphost = "mail.yourdomain.com"; // The address for your smtp server
$smtpport = 587; // Port, it's normal port 25 but some use other ports, so you have to check this for your needs.
$smtpuser = $from; // My login is the same as my email address, else put in your login name here.
$smtppass = "mysmtppassword"; // Your Password for your $smtpuser login name.

// Set auth to false if you don't need to do smth auth, like sending mail within your local network.
$smtpparams = array('host' => $smtphost,
'port' => $smtpport,
'auth' => true,
'username' => $smtpuser,
'password' => $smtppass);

// Compose the new mail
$message = new Mail_mime();
$message->setTXTBody(html2txt($sMailBody));
$message->setHTMLBody($sMailBody);

$body = $message->get();

$extraheaders = array("From" => $from, "Subject" => $sMailSubject);
$headers = $message->headers($extraheaders);

$mailobj = Mail::factory('smtp', $smtpparams);
$smtpstatus = $mailobj->send($sRecipientEmail, $headers, $body);

// We want to send the same status as the normal mail() does
if(PEAR::isError($smtpstatus)) {
// Error
$iSendingResult = false;
} else {
// no errors
$iSendingResult = true;
}

Now you have to comment out the next comming 'if' block like this:

/*
if( 'html' == $sEmailFlag) {
$sMailHeader = "Content-type: text/html; charset=UTF-8\r\n" . $sMailHeader;
$iSendingResult = mail( $sRecipientEmail, $sMailSubject, $sMailBody, $sMailHeader, $sMailParameters );
} else {
$sMailHeader = "Content-type: text/plain; charset=UTF-8\r\n" . $sMailHeader;
$sMailBody = html2txt($sMailBody);
$iSendingResult = mail( $sRecipientEmail, $sMailSubject, html2txt($sMailBody), $sMailHeader, $sMailParameters );
}
*/

Save the file and you'r done!

Quote · 9 Apr 2011
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.