Jim Lucas wrote:
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.

 $basePath = str_ireplace('public_html', '', $_SERVER['DOCUMENT_ROOT']);
 set_include_path(get_include_path() . PATH_SEPARATOR . basePath);
 require_once "$basePath/php" . '/Mail.php';


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;
  } else {
    $smtpStatus = false;

Jim Lucas

Thanks for the feedback. That's big help. I'm sending this revised code to my client to install on his Bluehost server.

Actually, I do check if EMAIL_MODE is defined; just didn't show it here.

And, I have debug mode that provides a more detailed error report. But, it doesn't help if it can't even find Mail

if (PEAR::isError($result))
    $mode = EMAIL_MODE;

throw new Exception("The email mode \"$mode\" does not work. Check the Applic email address and password in config file. <br /> Tech support required, use DISABLE_MAIL_SEND to debug. Error found in pearEmailSend().<br />" .

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to