Pear?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Pear?

    Hi, can anyone confirm whether the PEAR extension is loaded when you install PHP on this particular package? I need to get around the banning of PHP's mail() funtion

    #2
    Hi There,

    You can use the PHP PEAR function. please refer following article referred from webkami.com :-

    How to send email using pear mail when php's mail function doesn't work or gives error?

    PHP mail function is disabled by eukhost and many other hosting providers for anti spam and security reasons. PHP Mail can be used to send anonymous emails, spams and is vulnerable to form injections.

    You can still use a much better mailing function called PEAR:mail. Below is a sample code which you can use in any PHP file you create. Just follow the simple instructions below:

    Replace the variables in the following code.
    Use your email address/account created on same server.
    You don't need to have the file Mail.php, it is already installed as PEAR package

    <?php
    require_once "Mail.php";

    /**************************************************
    EDIT the following variables for your own use
    ************************************************** */
    $from = "Sender <[email protected]>";
    $to = "Recipient <[email protected]>";

    $subject = "Hi!"; //type in subject here

    $host = "mail.exampledomain.com"; // Your domain
    $username = "smtp_username"; // Your user / full email address
    $password = "smtp_password"; // Password to your email address



    /**************************************************
    ************************************************** */

    $body = "";

    foreach($_POST as $a => $b)
    {
    $body .= $a .": ". $b . "\n";
    }

    $headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject);
    $smtp = Mail::factory('smtp',
    array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

    $mail = $smtp->send($to, $headers, $body);

    if (PEAR::isError($mail)) {
    /**************************************************
    ERROR MESSAGE
    ************************************************** */
    ?>

    <p> <? echo $mail->getMessage(); ?> </p>
    <?
    /**************************************************/
    } else {
    /**************************************************
    SUCCESS MESSAGE
    ************************************************** */
    ?>
    <p>Message successfully sent!</p>
    <?
    /**************************************************/
    }
    ?>
    eUKhost - eNlight Cloud Hosting || eUKhost Knowledgebase
    Toll Free : 0808 262 0255 || Skype : mark_ducadi

    Comment


      #3
      Just like to add to this. You don't necessarily need to use the PEAR library. You can also use the SwiftMailer library as detailed in our blog post.

      Kind regards,
      Ben Stones.

      Comment


        #4
        Thanks, when PEAR's been installed I'll give it a go. (Neither are installed as standard on Windows.)

        Comment


          #5
          Originally posted by Phatman View Post
          Thanks, when PEAR's been installed I'll give it a go. (Neither are installed as standard on Windows.)
          Ah, I see. I was surprised when you said PEAR wasn't enabled for you, as PEAR is a very useful library for PHP developers, but may not be enabled and/or installed by default on our Windows servers. I have responded to your other thread regarding this.

          Kind regards,
          Ben Stones

          Comment


            #6
            Well PEAR is installed and I can send text emails no problem but when I try to send HTML formatted email using PEARS mime file include I get this error:

            "Warning: mail() has been disabled for security reasons in D:\Parallels\Plesk\Additional\PleskPHP5\Pear\Mail\ mail.php on line 153"

            The code I'm using is at the top of this here page:



            Is there a conflict between PEARS mail class?

            Hmmm, I'm now wondering if Swift might have been a better option lol.

            Comment


              #7
              Originally posted by Phatman View Post
              Well PEAR is installed and I can send text emails no problem but when I try to send HTML formatted email using PEARS mime file include I get this error:

              "Warning: mail() has been disabled for security reasons in D:\Parallels\Plesk\Additional\PleskPHP5\Pear\Mail\ mail.php on line 153"

              The code I'm using is at the top of this here page:



              Is there a conflict between PEARS mail class?

              Hmmm, I'm now wondering if Swift might have been a better option lol.
              Hello,

              Sorry for the late response. The reason being is because of this line:

              $mail =& Mail::factory('mail');
              Which specifies to PEAR to use the mail() function. See: http://pear.php.net/manual/en/packag...il.factory.php

              The first parameter of the factory() method needs to be "smtp" instead of "mail" in this case, and the second parameter would have SMTP information in an array variable - example:

              $smtp_info["host"] = "localhost";
              $smtp_info["port"] = "25";
              // ...
              $mail =& Mail::factory("smtp",$smtp_info);
              As you can see in the documentation:

              object &factory ( string $backend , array $params = array() )
              The second parameter is looking for an array, but is optional as it is not required if using mail. In this case, it is required.

              The URL I linked to shows the possible parameters, and for smtp:

              smtp

              $params["host"] - The server to connect. Default is localhost.

              $params["port"] - The port to connect. Default is 25.

              $params["auth"] - Whether or not to use SMTP authentication. Default is FALSE.

              $params["username"] - The username to use for SMTP authentication.

              $params["password"] - The password to use for SMTP authentication.

              $params["localhost"] - The value to give when sending EHLO or HELO. Default is localhost

              $params["timeout"] - The SMTP connection timeout. Default is NULL (no timeout).

              $params["verp"] - Whether to use VERP or not. Default is FALSE.

              $params["debug"] - Whether to enable SMTP debug mode or not. Default is FALSE.

              Mail internally uses Net_SMTP::setDebug .

              $params["persist"] - Indicates whether or not the SMTP connection should persist over multiple calls to the send() method.

              $params["pipelining"] - Indicates whether or not the SMTP commands pipelining should be used.
              This is showing the array values that can be provided to PEAR; you'd need to provide at least the host (server address - use localhost for sending mail on the same server), username, password and SMTP port. The SMTP port should be 25.

              If using SwiftMailer, I believe it allows you to choose between mail and smtp as well, so if you had mail being used via SwiftMailer, the same issue would occur.

              Please feel free to let us know if you require any further assistance on this.

              Kind regards,
              Ben Stones.

              Comment


                #8
                Thanks Ben, I've now aquainted myself with PEAR, it seemed it all bit arcane at first, I'm still getting to grips with PHP!

                Comment


                  #9
                  Originally posted by Phatman View Post
                  Thanks Ben, I've now aquainted myself with PEAR, it seemed it all bit arcane at first, I'm still getting to grips with PHP!
                  No problem. You're most welcome to request assistance if you have any further issues using PEAR or any questions. We have several tutorials on PHP you may be interested in reading regarding PHP.

                  Kind regards,
                  Ben Stones.

                  Comment


                    #10
                    Hope you've managed to get your forms all up and running now .
                    David Smith
                    Managing Director
                    DPS Computing Limited

                    - Massive update! (September 2011) - It's now not neglected!!
                    - New Site (10/2009)

                    Comment


                      #11
                      Yes, I think after re-applying permissions to various folders getting FTP sorted out and database connectivity fixed plus changing email scripts over we're about there! I admit the paramatised email script is a sensible thing. I also think password authorisation should be introduced on IIS CDO mail forms.

                      Comment

                      Working...
                      X