0
votes

how excatly do i make t work ? I need to use the Zend framework for sending mails. But im unable to include the framework proberly in my php file. the problem might be caused by the fact im using a shared hosting service.

I have done the following

  1. downloaded a linux tgz distribution with the framework in version 2.x.
  2. unzipped it and uploaded the folder via. ftp to my shared hosting.
  3. I placed the Zend folder in the root.
  4. I dont have acces to the php.ini file, so i created a new one with the following content.

    safe_mode = off
    SMTP = localhost
    smtp_port = 26
    sendmail_from = web15.meebox.net
    include_path = /home/sammensp/public_html/Zend/library
    
  5. I placed the following code into a php file to test if the framework worked.

    require_once 'Zend/Mail/Message.php';
    use Zend\Mail;
    $mail = new Mail\Message();
    $mail->setBody('This is the text of the email.');
    $mail->setFrom('[email protected]', 'Sender\'s name');
    $mail->addTo('[email protected]', 'Name o. recipient');
    $mail->setSubject('TestSubject');
    $transport = new Mail\Transport\Sendmail();
    $transport->send($mail);
    

the problem is that it doesnt work i get the following errors.

    Warning:  require_once(Zend/Mail/Message.php) [<a href='function.require-
    once'>function.require-once</a>]: failed to open stream: No such file or directory in     
    /home/sammensp/public_html/mobile/test.php on line 23

    Fatal error:  require_once() [<a href='function.require'>function.require</a>]: Failed  
    opening required 'Zend/Mail/Message.php'    
    (include_path='/home/sammensp/public_html/Zend/library') in   
    /home/sammensp/public_html/mobile/test.php on line 23

my web app and the test.php file is located at /public_html/mobile/test.php i have set the include path to the following include_path = /home/sammensp/public_html/Zend/library

can you help me with a solution to what i have done wrong and how i fix it ?

2
Are you sure that the settings from the php.ini you've created actually get applied? Try to add the library folder to the include path using set_include_path(). - Niko
verify your ini settings are being used via ini_get() or phpinfo. if needed, use ini_set() - goat
Check with your hosting provider because ultimately they determine what is allowed for you to do. If they don't support what you need, you can always switch. - jsteinmann
I checked that the include path is working, but still something is wrong..... - CG Christen Christensen
ok so i tried using a different mail wrapper called php mailer. it worked but didnt do the trick. I never got zend mail to work, but I guess it doesnt matter. I properly would fix my root problem. which is that hotmail puts my mail into the junk filter - CG Christen Christensen

2 Answers

0
votes

You can't just put a php.ini in the webserver root, it won't be loaded. Use a .htaccess (assuming you are on an apache server) file to set PHP settings (php_value include_path ".:/usr/www/your_user_folder/your_website_folder/includes") or use set_include_path() in your php files.

Both methods might be disabled by your host.

0
votes

Unless you need to allow access to the framework by all projects on your server, you don't need to include it on a global level. In fact, most people that host projects don't have access to modify the php.ini file (except for a loval dev environment).

ZF is just a library folder. It's very similar to what people do that add zend framework library to their say codeigniter projects or similar. It's designed to be loosely coupled so it can be utilized any way you want.

Download ZF and upload it to wherever you like in your public_html folder or wherever. Use set_include_path() and sample code below:

<?php
    // Define relative path to ZendFramework in public_html
    define('ZF_PATH', '/../../../lib/php/zendframework');

    // Define path to application directory
    defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

    // Define real path to ZendFramework if it's not yet included in include_path
    if(!strpos(get_include_path(), 'zendframework'))
        define('ZF_REAL_PATH', realpath(APPLICATION_PATH . ZF_PATH));
    else define('ZF_REAL_PATH', '');

    // Updating include_path
    set_include_path(implode(PATH_SEPARATOR, array(ZF_REAL_PATH, get_include_path(),)));

    // Done! the rest of the code might be unnecessary in your case.
    require 'Zend/Application.php'; 

    // Create application, bootstrap, and run
    $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
    $application->bootstrap()->run();