#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0

    Mail function simply echos PHP file to page


    I'm trying to get a copy of an existing PHP site up and running on my Windows 2008 Server. I've installed PHP 5.4 using the Microsoft Web Platform Installer (v4.5). The installation seemed to go fine, and I've managed to display the phpinfo page.

    There's a contact form on the site which captures user details and sends an email - the code of the php which is executed on form submission is below. This functionality works on the live site, but when I submit the form on my Windows server it simply echos the content of the .php file (i.e. the code below) to the page.

    I've configured the SMTP server in php.ini to use localhost on port 25, and have successfully sent an outbound email using the local SMTP server.

    Can anyone suggest why this is happening?

    PHP Code:
    <?


    $strContents 
    "

    This is an email from the xxxxx website\n \n<br><br>
    Sender: \t "
    .$_POST['firstName']." \n<br>
    Email: \t "
    .$_POST['_sendersemail']." \n<br>
    Telephone: \t "
    .$_POST['phoneNumber']." \n<br>
    Company: \t "
    .$_POST['enquiry']." \n<br>
    "
    ;

    if (!
    sendMail(array('subject' => 'Contact Form''contents' => $strContents'recipients' => array(
        array(
    'emailAddress' => 'info@xxxxx.com')
    )))) {
        
    header('Location: ' $_POST['missing_fields_redirect']);
    }



    function 
    sendMail($arrMail) {
        
        if (!
    array_key_exists('contents'$arrMail)) {return false;} else {$strContents $arrMail['contents'];}
        if (!
    array_key_exists('recipients'$arrMail)) {return false;}
        
        
    $headers "From: xxxxxx contact form <noreply@xxxxxxx> \n"
        
    $headers .= "Return-Path: <noreply@xxxxx>\n"
        
    $headers .= "MIME-Version: 1.0\n"
        
    $headers .= "Content-Type: text/html; charset=UTF-8\n"
        
        foreach (
    $arrMail['recipients'] as $arrRecipient) {
            if (!
    mail($arrRecipient['emailAddress'],$arrMail['subject'],$strContents$headers)) {return false;}
        }
        
        return 
    true;
        
    }

    header('Location: ' $_POST['redirect']);

    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    868
    Rep Power
    275
    the first thing I am seeing is that you are trying to use short-tags which is probably not turned ON in your webserver.
    change your opening php tags from <? to <?php and see if that helps.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    2
    Rep Power
    0
    That was it! Many thanks

IMN logo majestic logo threadwatch logo seochat tools logo