Al wrote:
> I've got script that uses the pear Mail class and have had problems on
> some shared hosts with the include path to Mail. E.g., Blue Host insists
> the site owner must change the php.ini file. I'd rather not expect them
> to do that.
>
> Can you folks critique this approach for me.
>
> if(EMAIL_MODE=='smtp'){
> $basePath = str_ireplace('public_html', '', $_SERVER['DOCUMENT_ROOT']);
> set_include_path(get_include_path() . PATH_SEPARATOR . basePath);
> require_once "$basePath/php" . '/Mail.php';
> $smtpStatus=(class_exists('Mail'))?true:false;
> }
>
> Thanks....
>
How about this
# Check to see if the constant is defined BEFORE you try to use it.
if ( defined('EMAIL_MODE') && EMAIL_MODE == 'smtp' ) {
# You might want to do more checking on the path. Checking to see if it
# has double forward slashes at the end would be the first place to start
$basePath = str_ireplace('public_html', '', $_SERVER['DOCUMENT_ROOT']);
# IMO, no improvement needed here
set_include_path(get_include_path() . PATH_SEPARATOR . $basePath);
# Well, it is what it is
$filename = "{$basePath}/php/Mail.php";
# Check to see if file exists and is readable BEFORE you try including it
if ( is_file($filename) && is_readable($filename) ) {
require_once $filename;
$smtpStatus=(class_exists('Mail'))?true:false;
} else {
$smtpStatus = false;
}
}
Jim Lucas
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php