Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ashebrian
Forum Contributor
Posts: 103
Joined: Sat Feb 02, 2008 8:01 pm

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESP

Post by ashebrian »

* Moved to PHP Code which the place for questions about non-working code. Code Critique is for reviews of working code.

Hi guys,

I made a big mistake. I tried to just delete a few spaces on all my web pages in dreamweaver, what it did was pushed all my codes together. so now i had to fix them all up again.

However, i am struggling with this tell a friend script as i now recieve an error when it worked before.

I recieved an error:
Parse error: syntax error, unexpected T_SL in line ...(at this line $theForm = <<<EOD )
However, i sorted this problem by fixing up the whitespace after <<<EOD.

BUT i recieved another error......
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in.....if ($_POST['your_email'] != "") {
I have tried to sort this but i couldn't find the solution to this error. I will be grateful for anyone who helps.

My code is as follows:

Code: Select all

<?php
            // ************Begin Configure***************
            //Put your website name between the quotes below:
            $websiteName = "My Name";
            //Put your website address between the quotes below:
            $websiteAddress = "www.......com";
            // If you have a privacy policy, put in the link title: 
            $privacyPolicyLinkText = "Privacy Policy";
            // Put in the "" the url to you your privacy policy, if you have one,
            $privacyPolicyLinkURL = "hkj.php";
            // Change the 0 to a 1 below, 
            //if you want to recieve a notice when people are refered:
            $notice = 1;
            //Put your email address in the " " if you changed the notice to 1
            $adminEmail = "my@mail.ie";
            //Put the subject line text you want the email to read in the  "":
            $subject = "Check out ......";
            // Put your default message intro text in the first set of quotes below
            //This is what the people who are referred will see
            //along with any personal message entered by the referer.
            $defaultMessageIntro = "You friend has visited .......: " . "\n" ; 
            //Put in the "" your default close (this will be at the end of the message):
            $defaultMessageClose = "..........";
            // ************End Configure****************
            // Set the link that will be in intro/invite and used to send the referer back
            if (isset($_POST['link'])) {
                $link = $_POST['link'];
            } else {
                if (empty($_SERVER['HTTP_REFERER'])) {
                    $link = 'http://' . $websiteAddress;
                } else {
                    $link = $_SERVER['HTTP_REFERER']; 
                } 
            }
            // Add the link to the intro
            $defaultMessageIntro = $defaultMessageIntro . $link . "\n";
            //Adds a space infront of the subject line (to add a name latter
            $subject = ' ' . $subject; ?>
            <?php 
            function doTellForm ($privacyPolicyLinkText, $privacyPolicyLinkURL, $defaultMessageIntro, $link) {
                $theForm = <<<EOD
<form name="tellForm" method="post" action="">
                    <table width="500px" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>
                                <div align="center"><b>Your name:</b></div>
                            </td>
                            <td>
                                <div align="center"><input name="your_name" type="text" id="your_name"></div>
                            </td>
                            <td>
                                <div align="center"><b>Your email:</b></div>
                            </td>
                            <td>
                                <div align="center"><input name="your_email" type="text" id="your_email"></div>
                            </td>
                        </tr>
                    </table>
                    <p>&nbsp;</p>
                    <table width="500px" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>
                                <div align="center"></div>
                            </td>
                            <td>
                                <div align="center"></div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="center"><b>Enter the name(s) of your friend(s):</b></div>
                            </td>
                            <td>
                                <div align="center"><b>Enter the email(s) of your friend(s):</b></div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="center"><input name="friend_name1" type="text" id="friend_name1"></div>
                            </td>
                            <td width="50%">
                                <div align="center"> <input name="friend_email1" type="text" id="friend_email1"></div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="center"> <input name="friend_name2" type="text" id="friend_name2"></div>
                            </td>
                            <td>
                                <div align="center"> <input name="friend_email2" type="text" id="friend_email2"></div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="center"><input name="friend_name3" type="text" id="friend_name3"></div>
                            </td>
                            <td>
                                <div align="center"> <input name="friend_email3" type="text" id="friend_email3"></div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div align="center"> 
                                    <p>
                                        <b>Your Message (optional):</b> 
                                        <input name="tellsubmit" type="hidden" id="tellsubmit4" value="doTheSend">
                                        <input name="link" type="hidden" id="link" value="$link"><br>
                                        <textarea name="message" cols="50" rows="5" id="textarea">$defaultMessageIntro</textarea>
                                    </p>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <p align="center"> <input type="submit" name="Submit" value="Send It"></p>
                                <p align="center"><a href="$privacyPolicyLinkURL" target="_blank">$privacyPolicyLinkText</a></p>
                            </td>
                        </tr>
                    </table>
                    <div align="center"></div>
                </form>
                EOD; 
                echo ($theForm);
            }
            ?>
            <?php 
            function spamcheck($array) {
            # returns true if data is ok, otherwise false if it is spam-looking
                return (!preg_match("/(MIME-Version:|Content-Type:|\n|\r)/i", join('',array_values($array)) ));
            }
            function myMailFunction($mailto, $subject, $message, $headers, $defaultMessageClose, $adminEmail, $notice) {
                $message = $message . "\n\n" . $defaultMessageClose;
                // Check for suspected spam content
                if (!spamcheck(array($mailto,$subject,$headers))) {
                    die('no spam please');
                }
                if (@mail($mailto, $subject, $message, $headers)) {
                    echo ('<p>Your message was successfully sent to ' . $mailto . '</p>');
                    if ($notice == 1) {
                        $message = "From email " . $headers . "\n\n" . "To email " . "\n\n" . $mailto . "\n\n" . $message;
                        @mail($adminEmail, "Referal notice", $message);
                    }
                } else {
                    // This echo's the error message if the email did not send.  
                    echo('<p>Mail could not be sent to ' . $mailto .  ' Please use your back button to try them again.</p>');
                }
            }
            ?>
            <?php function doTell ($notice, $adminEmail, $subject, $websiteName, $defaultMessageClose, $link) {
                if ($_POST['your_email'] != "") {
                    $headers = 'From: ' . $_POST['your_name'] . '<' . $_POST['your_email'] . '>';
                    } else {
                        $headers = 'From: ' . $websiteName . '<' . $adminEmail . '>';
                    }
                    if ($_POST['friend_email1'] != "") {
                        $mailto1 = $_POST['friend_email1'];
                        //This tacs the name onto the subject line
                        $subject1 = $_POST['friend_name1'] . $subject; 
                        //This tacs the name onto the message
                        $message1 = $_POST['friend_name1'] . "\r\n" . $_POST['message'];
                        myMailFunction($mailto1, $subject1, $message1, $headers, $defaultMessageClose, $adminEmail, $notice);
                    }
                    if ($_POST['friend_email2'] != "") {
                        $mailto2 = $_POST['friend_email2'];
                        //This tacs the name onto the subject line
                        $subject2 = $_POST['friend_name2'] . $subject; 
                        //This tacs the name onto the message
                        $message2 = $_POST['friend_name2'] . "\r\n" . $_POST['message'];
                        myMailFunction($mailto2, $subject2, $message2, $headers, $defaultMessageClose, $adminEmail, $notice);
                    }
                    if ($_POST['friend_email3'] != "") {
                        $mailto3 = $_POST['friend_email3'];
                        //This tacs the name onto the subject line
                        $subject3 = $_POST['friend_name3'] . $subject; 
                        //This tacs the name onto the message
                        $message3 = $_POST['friend_name3'] . "\r\n" . $_POST['message'];
                        myMailFunction($mailto3, $subject3, $message3, $headers, $defaultMessageClose, $adminEmail, $notice);
                    }
                    $return = <<<EOD <p align="center"><a href="$link">Return to the page you left.</a></p> EOD; 
                    echo ($return);    
                }
                ?>
                <?php 
                if (isset($_POST['tellsubmit'])) {
                    doTell($notice, $adminEmail, $subject, $websiteName, $defaultMessageClose, $link);
                } else {
                    doTellForm($privacyPolicyLinkText, $privacyPolicyLinkURL, $defaultMessageIntro, $link);
                }
                ?>
ashebrian
Forum Contributor
Posts: 103
Joined: Sat Feb 02, 2008 8:01 pm

Re: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESP

Post by ashebrian »

ok.........I have started using ' instead of the (unusual) heredoc syntax. As this works and displays the form properly but ...what it doesn't do is get the data from the variables like $privacyPolicyLinkURL etc.
ashebrian
Forum Contributor
Posts: 103
Joined: Sat Feb 02, 2008 8:01 pm

Re: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESP

Post by ashebrian »

ok....i changed my code altogether. i just put it in a form with send mail.

however, i have used a dreamweaver onclick. I don't like their js script as its always a mess.

Code: Select all

onclick="MM_validateForm('name','','R','email','','RisEmail','friendname1','','R','friendemail1','','RisEmail','friendemail2','','NisEmail','friendemail3','','NisEmail','text','','R');return document.MM_returnValue" />
is there a way i can change this code to work the same way??
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHI

Post by McInfo »

Regarding your original post:

Some of your form field names do not match your $_POST variables. Your submit button is named "Submit" but you are checking $_POST['tellsubmit'].

When using heredoc syntax, the opening identifier (<<<IDENTIFIER) must be followed immediately by a newline. Likewise, the closing identifier (IDENTIFIER;) must be preceded with and followed by a newline.

PHP Manual: Heredoc Syntax

Edit: 'your' -> 'you'; 'your' -> 'the';

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Mon Jun 14, 2010 3:14 pm, edited 1 time in total.
ashebrian
Forum Contributor
Posts: 103
Joined: Sat Feb 02, 2008 8:01 pm

Re: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESP

Post by ashebrian »

as i have said:
ok....i changed my code altogether. i just put it in a form with send mail.
the form is now:

Code: Select all

<form method="post" action="">
                    <table width="500px" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>
                                <div align="center"><b>Your name:</b></div>
                            </td>
                            <td>
                                <div align="center"><input name="name" type="text" id="name" /></div>
                            </td>
                            <td>
                                <div align="center"><b>Your email:</b></div>
                            </td>
                            <td>
                                <div align="center"><input name="email" type="text" id="email" /></div>
                            </td>
                        </tr>
                    </table><p>&nbsp;</p>
                    <table width="500px" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>
                                <div align="center"></div>
                            </td>
                            <td>
                                <div align="center"></div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="center"><b>Enter the name(s) of your friend(s):</b></div>
                            </td>
                            <td>
                                <div align="center"><b>Enter the email(s) of your friend(s):</b></div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="center"><input name="friendname1" type="text" id="friendname1" /></div>
                            </td>
                            <td width="50%">
                                <div align="center"><input name="friendemail1" type="text" id="friendemail1" /></div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div align="center"><input name="friendname2" type="text" id="friendname2" /></div>
                            </td>
                            <td>
                                <div align="center"><input name="friendemail2" type="text" id="friendemail2" /></div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div align="center"> 
                                    <p>
                                        <b style="vertical-align:top">Your Message (optional):</b> 
                                        <textarea name="text" cols="50" rows="5">I found this great website which I believe you would be interested in. 
Click here to visit the page: <?php echo $QUERY_STRING ?></textarea>
                                    </p>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <p align="center"><input type="submit" value="   Send   " name="Submit" onclick="MM_validateForm('name','','R','email','','RisEmail','friendname1','','R','friendemail1','','RisEmail','friendemail2','','NisEmail','friendemail3','','NisEmail','text','','R');return document.MM_returnValue" /></p>
ashebrian
Forum Contributor
Posts: 103
Joined: Sat Feb 02, 2008 8:01 pm

Re: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESP

Post by ashebrian »

problem sorted ..... cheers for trying to help..... i went back to <<<EOD and its all working fine now.
Post Reply