Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP mailer issue/file path issue

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #171211
    rwchampin
    Participant

    ok so i have a contact.php that handles all php mailing internally within the contact.php. it works fine untill i add the mail object from my 3rd party library and use the require_once call to include the actual class. these line are commented out and the contact form performs fine…..im also getting two errors relating to the filepath….im not insane lol my filepath’s are correct….im new to php so i think its something else but just incase heres my path:
    project folder/inc/phpmailer/class.phpmailer.php

    and here’s my official PHP errors:

    Warning: require_once(inc/phpmailer/class.phpmailer.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/For The Bold v2/contact.php on line 76

    Fatal error: require_once(): Failed opening required ‘inc/phpmailer/class.phpmailer.php’ (include_path=’.:/Applications/MAMP/bin/php/php5.4.10/lib/php’) in /Applications/MAMP/htdocs/For The Bold v2/contact.php on line 76

    and heres my code:

    <?php 
    

    error_reporting(E_ALL);
    ini_set(‘display_errors’, 1);

        if($_SERVER["REQUEST_METHOD"] == "POST"){
    
            $name = trim($_POST["name"]);
            $email = trim($_POST["email"]);
            $phone = trim($_POST["phone"]);
            $company_name = trim($_POST["company_name"]);
            $cityState = trim($_POST["cityState"]);
            $website = trim($_POST["website"]);
            $years = trim($_POST["years"]);
            $competitors = trim($_POST["competitors"]);
            $target = trim($_POST["target"]);
            $desc = trim($_POST["desc"]);
            $range = trim($_POST["range"]);
    
    
            if(isset($_POST['website-job'])){
                $website = "true";
            }
            else{
                $website = "false";
            }
    
            if(isset($_POST['app-job'])){
                $app = "true";
            }
            else{
                $app = "false";
            }
    
            if(isset($_POST['branding-job'])){
                $branding = "true";
            }
            else{
                $branding = "false";
            }
    
            if(isset($_POST['print-job'])){
                $print = "true";
            }
            else{
                $print = "false";
            }
    
            if(isset($_POST['marketing-job'])){
                $marketing = "true";
            }
            else{
                $marketing = "false";
            }
    
            if(isset($_POST['corporate-job'])){
                $corporate = "true";
            }
            else{
                $corporate = "false";
            }
    
    
            if ($name == "" OR $phone == "" OR $email == "" OR $desc == "" OR $target == "" OR $range == "0.00"){
                echo "You must answer all fields with an *";
                exit;
            }
    
            foreach( $_POST as $value ){
                if( stripos($value,'Content-Type:') !== FALSE){
                    echo "There was a problem with your ISP :(";
                    exit;
                }
        }
    
        require_once("inc/phpmailer/class.phpmailer.php");
        $mail = new PHPMailer();
    
    
        if($mail->ValidateAddress($email)){
            echo "You must enter a valid email!";
            exit;
        }
    
        $email_body = "";
        $email_body = $email_body . "Name: " . $name . "\n";
        $email_body = $email_body . "Email: " . $email . "\n";
        $email_body = $email_body . "Message: " . $message;
    
    
    
    
    
    
    
        header("Location: contact.php?status=thanks");
        exit;
        }
    
    
    
    
    
         $current = 'contact';
    
    include("inc/header.php"); 
    

    ?>
    <body>

    &lt;!-- TITLE SECTION --&gt;
    &lt;section class="heading-lg center hero" id="top"&gt;Meet Our Gate Keeper. He Bites.
        &lt;h4 class="center"&gt;Plan Your Project Below&lt;/h4&gt;
    &lt;/section&gt;
    &lt;?php include("inc/navbar.php"); 
    
     if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?&gt;
        Thanks for the Email, we'll be in touch!
    &lt;?php } else { ?&gt;
    
    <div>
            &lt;section class="heading-sm center margin-top"&gt;The Basics&lt;/section&gt;
        &lt;form method="post" action="contact.php"&gt; 
            &lt;!-- THE BASICS --&gt;
            <div>
                <div>
                    &lt;input type="text" class="form-control" name="name" placeholder="Full Name*"&gt;
                </div>
                <div>
                    &lt;input type="text" class="form-control" name="email" placeholder="Email*"&gt;
                </div>
                <div>
                    &lt;input type="text" class="form-control" name="phone" placeholder="Phone*"&gt;
                </div>
            </div>
    
            &lt;!-- YOUR COMPNAY --&gt;
            <div>
                <div>
                    &lt;input type="text" class="form-control" name="company_name" placeholder="Company Name"&gt;
                </div>
                <div>
                    &lt;input type="text" class="form-control" name="cityState" placeholder="City, State"&gt;
                </div>
                <div>
                    &lt;input type="text" class="form-control" name="website" placeholder="Website"&gt;
                </div>
                &lt;input type="text" style="display: none;"&gt;
            </div>
    
    
    
    
            &lt;section class="heading-sm center margin-top"&gt;Your Company&lt;/section&gt;
    
            <div>
                <div>
                    &lt;input type="text" class="form-control" name="years" placeholder="Years iN bUSINESS"&gt;
                </div>
                <div>
                    &lt;input type="text" class="form-control" name="competitors" placeholder="Competition"&gt;
                </div>
                <div>
                    &lt;input type="text" class="form-control" name="target" placeholder="Target Audience"&gt;
                </div>
            </div>
    
    
        <div>   
            <div>
                <div>
                    &lt;textarea class="form-control margin-bottom" name="desc" rows="3"placeholder="Company Description*"&gt;&lt;/textarea&gt;
                </div>
            </div>
        </div>  
    
            &lt;!-- CHECKBOXES --&gt;
            &lt;label class="heading-sm center"&gt;Type Of Project&lt;/label&gt;
            <div>
    
                        <div>
                            <div>
                                <div>
                                    &lt;input type="checkbox" id="c1" name="corporate-job" value="corporate-job"&gt;
                                    &lt;label for="c1"&gt;<span>
    
                                    <p>Corporate</p></span>&lt;/label&gt;
                                </div>
                            </div>
                        </div>  
    
                        <div>
                            <div>   
                                <div>
                                    &lt;input type="checkbox" id="c2" name="website-job" value="website-job"&gt;
                                    &lt;label for="c2"&gt;<span><p>Website</p></span>&lt;/label&gt;
                                </div>
                            </div>
                        </div>  
    
                        <div>
                            <div>   
                                <div>
                                    &lt;input type="checkbox" id="c3" name="app-job" value="app-job"&gt;
                                    &lt;label for="c3"&gt;<span><p>App</p></span>&lt;/label&gt;
                                </div>
                            </div>
                        </div>  
    
                        <div>
                            <div>   
                                <div>
                                    &lt;input type="checkbox" id="c4" name="branding-job" value="branding-job"&gt;
                                    &lt;label for="c4"&gt;<span><p>Branding</p></span>&lt;/label&gt;
                                </div>
                            </div>
                        </div>  
    
                        <div>
                            <div>
                                <div>   
                                    &lt;input type="checkbox" id="c5" name="print-job" value="print-job"&gt;
                                    &lt;label for="c5"&gt;<span><p>Print</p></span>&lt;/label&gt;
                                </div>
                            </div>
                        </div>  
    
                        <div>
                            <div>
                                <div>   
                                    &lt;input type="checkbox" id="c6" name="marketing-job" value="marketing-job"&gt;
                                    &lt;label for="c6"&gt;<span><p>Marketing</p></span>&lt;/label&gt;
                                </div>
                            </div>
                        </div>
    
    
            </div>
    
    
            &lt;!-- BUDEGET SLIDER --&gt;
            <div>
                <div></div>
                <div>
                    &lt;h4 class="center"&gt;Project Budget&lt;/h4&gt;
                    &lt;input type="range" name="range" min="0" max="10000" step="50" value="0" /&gt;
                    &lt;output for="range" class="heading-sm" &gt;&lt;/output&gt;
                </div>
                <div></div>
            </div>
    
    
            &lt;!-- WHERED YOU FIND US --&gt;
            &lt;label class="heading-sm center"&gt;Have you been stalking us? We hope so...&lt;/label&gt;
            <div>
                <div></div>
                <div>
    
                    &lt;input type="text" class="form-control" name="reference" placeholder="Where did you find us?"&gt;
                </div>
                <div></div>
    
            </div>
    
            &lt;!-- SUBMIT --&gt;
            <div>
                <div></div>
                <div>
                    &lt;button type="submit" class="btn btn-default contact-btn btn-block"&gt;Submit&lt;/button&gt;
                </div>
                <div></div>
            </div>
    </div>  &lt;/form&gt;   
    </div>      
    &lt;?php } ?&gt;
    

    <?php include(“inc/footer.php”); ?>

    <?php include(“inc/scripts.php”); ?>
    </body>
    </html>

    #171217
    __
    Participant

    If you’re trying to require this:

    inc/phpmailer/class.phpmailer.php
    

    from here:

    /Applications/MAMP/htdocs/For The Bold v2/contact.php
    

    Then the file path you are actually requesting is this:

    /Applications/MAMP/htdocs/For The Bold v2/inc/phpmailer/class.phpmailer.php
    

    Is this what you expected? is this where the file actually is?

    I would suggest always using absolute paths when loading files. This way, there is never any question about whether or not you have the path correct. The easiest way to do this is to use $_SERVER['DOCUMENT_ROOT']:

    require_once "{$_SERVER['DOCUMENT_ROOT']}/inc/phpmailer/class.phpmailer.php";
    // or wherever your file is
    // (this example assumes that your document root is /Applications/MAMP/htdocs )
    

    (As a side note, I would strongly advise against using spaces in file names/ paths.)

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.