send a friend php code help

Discussion in 'PHP' started by lasvegascom, Jan 23, 2006.

  1. #1
    I need help with this code. This is the 2nd page of the code. The first page has the form and everything is fine with it. Basically I want the response message to be within the body of the html page (see bolded code for location ) but this code is just showing the message and not the rest of my html page like my logo (see italicized code for location). Can anyone please help?

    <?php
    $page_to_send = $_GET['page'] . ".php";
    $domain = "http://www.domainname.com/";
    $complete_url = $domain . $page_to_send;

    if (isset($_POST['submit'])) {
    $sendername = $_POST['sendername'];
    $senderemail = $_POST['senderemail'];
    $recipname = $_POST['recipname'];
    $recipemail = $_POST['recipemail'];
    $custmessage = $_POST['message'];
    $urltosend = $_POST['urlsent'];

    $staticmsg = "Hi $recipname! \n Your Colleague $sendername has recommended that you read this article from domain name with the following message: \n $custmessage.";
    $staticmsg = "$urltosend";
    $staticmsg = "SITE PROMOTION TEXT AREA";
    $staticmsg = "SITE PROMOTION TEXT AREA";
    $staticmsg = "SITE PROMOTION TEXT AREA";

    $ipaddress = $_SERVER['REMOTE_ADDR'];

    $subject = "A colleague has recommended this article!";
    $headers = "From: My Domain \r\n";
    $headers .= "Reply-To: $senderemail";

    if (mail($recipemail,$subject,$staticmsg,$headers)){
    echo "<p>Success. Your message was sent. Go back to the <a href=\"$urltosend\">page you were previously browsing</a>?</p>";
    } else {
    echo "<p>Your message could not be sent at this time. Go back to the <a href=\"$urltosend\">page you were previously browsing</a>?</p>";
    }

    } else {
    ?>
    <html>
    <head>
    <title>PAGE NAME</title>
    <meta name="robots" content="noindex,nofollow">
    <link href="style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" language="JavaScript" src="scripts/rollover.js"></script>


    <table width="600" border="0">
    <tr>
    <td colspan="3"><div align="left"><a href="index.htm"><img src="images/logo.gif" alt="" width="313" height="80" border="0"></a><br>
    <br>
    </div></td>
    </tr>
    <tr>
    <td width="60">&nbsp;</td>
    <td width="480" class="txt">Thanks for recommeding our article. An e-mail has been sent to <b>$recipemail</b>.<br><br></td>
    <td width="60">&nbsp;</td>
    </tr>
    <tr>
    <td width="60">&nbsp;</td>
    <td width="480" align="center"><a href=\"$urltosend\">Back to the Article</a></td>
    <td width="60">&nbsp;</td>
    </tr>
    </table>
    </body>
    </html>
    <?php
    }
    ?>
     
    lasvegascom, Jan 23, 2006 IP
  2. blinxdk

    blinxdk Peon

    Messages:
    660
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I wouldn't stop the php but echo the html instead.
     
    blinxdk, Jan 23, 2006 IP
  3. lasvegascom

    lasvegascom Peon

    Messages:
    438
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have no clue what that means as I do not know anything about php. I just found this code on like hotscripts or one of those sites and I am trying to adjust it to what I want.
     
    lasvegascom, Jan 23, 2006 IP
  4. blinxdk

    blinxdk Peon

    Messages:
    660
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Find:

    } else {
    ?>

    Replace with:

    } else {
    echo '


    Find:

    <?php
    }

    Replace with:

    ';
    }
    ?>

    Try that and see if it works.
     
    blinxdk, Jan 23, 2006 IP
  5. lasvegascom

    lasvegascom Peon

    Messages:
    438
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    no it didn't work. It still showed the "Success. Your message was sent. Go back to the page you were previously browsing?" message and not anything within the html code.

    I don't even want it to show that part at all. I want it so when it is a success it shows:
    Thanks for recommeding our article. An e-mail has been sent to <b>$recipemail</b>.

    and when it fails it shows:
    Your message could not be sent at this time. Go back to the <a href=\"$urltosend\">page you were previously browsing</a>
     
    lasvegascom, Jan 23, 2006 IP
  6. lasvegascom

    lasvegascom Peon

    Messages:
    438
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I think I have it working except one little piece. When it is succesful it shows the message I want except the email is not showing. I am guessin that part of the code is messed up a little. It is the bolded piece below.

    <?php
    $page_to_send = $_GET['page'] . ".php";
    $domain = "http://www.domainname.com/";
    $complete_url = $domain . $page_to_send;

    if (isset($_POST['submit'])) {
    $sendername = $_POST['sendername'];
    $senderemail = $_POST['senderemail'];
    $recipname = $_POST['recipname'];
    $recipemail = $_POST['recipemail'];
    $custmessage = $_POST['message'];
    $urltosend = $_POST['urlsent'];

    $staticmsg = "Hi $recipname! \n Your Colleague $sendername has recommended that you read this article from domain name with the following message: \n $custmessage.";
    $staticmsg = "$urltosend";
    $staticmsg = "SITE PROMOTION TEXT AREA";
    $staticmsg = "SITE PROMOTION TEXT AREA";
    $staticmsg = "SITE PROMOTION TEXT AREA";

    $ipaddress = $_SERVER['REMOTE_ADDR'];

    $subject = "A colleague has recommended this article!";
    $headers = "From: My Domain \r\n";
    $headers .= "Reply-To: $senderemail";
    }
    ?>
    <html>
    <head>
    <title>PAGE NAME</title>
    <meta name="robots" content="noindex,nofollow">
    <link href="style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" language="JavaScript" src="scripts/rollover.js"></script>

    <table width="600" border="0">
    <tr>
    <td colspan="3"><div align="left"><a href="index.htm"><img src="images/logo.gif" alt="" width="313" height="80" border="0"></a><br>
    <br>
    </div></td>
    </tr>
    <tr>
    <td width="60">&nbsp;</td>
    <td width="480" class="txt">
    <?php
    if (mail($recipemail,$subject,$staticmsg,$headers)) {
    echo 'Thanks for recommeding our article. An e-mail has been sent to <b><?="$recipemail"; ?></b>.';
    } else {
    echo 'Your message could not be sent at this time. Go back to the <a href=\"$urltosend\">page you were previously browsing</a>';
    }
    ?>

    <br><br></td>
    <td width="60">&nbsp;</td>
    </tr>
    <tr>
    <td width="60">&nbsp;</td>
    <td width="480" align="center"><a href=\"$urltosend\">Back to the Article</a></td>
    <td width="60">&nbsp;</td>
    </tr>
    </table>
    </body>
    </html>
     
    lasvegascom, Jan 23, 2006 IP
  7. blinxdk

    blinxdk Peon

    Messages:
    660
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yup it's messed up, you start php again without closing it (the <? ?> tags) - change it to:

    echo 'Thanks for recommeding our article. An e-mail has been sent to <b>$recipemail</b>.';
     
    blinxdk, Jan 24, 2006 IP
  8. Salsa

    Salsa Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    ...except I think you'll need to put it in double quotes, like:

    echo "Thanks for recommeding our article. An e-mail has been sent to <b>$recipemail</b>.";

    If you use single quotes, you have to concatinate, like:

    echo 'Thanks for recommeding our article. An e-mail has been sent to <b>'.$recipemail.'</b>.';

    Salsa
    _______
     
    Salsa, Jan 24, 2006 IP
  9. blinxdk

    blinxdk Peon

    Messages:
    660
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You're right, sorry for bringing the single quotes into it all and fail to notice them myself later :)
     
    blinxdk, Jan 24, 2006 IP
  10. lasvegascom

    lasvegascom Peon

    Messages:
    438
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Ok. So far so good, but I got three more questions.

    #1 - I want to put the link to the send a friend form on my article pages and I want it to be a 600x500 pop-up.
    <a href="tellafriend.php?page=<?=$page;?> class="a_link">Email a Colleague</a>

    Is this the correct code to use?

    #2 - It is not sending the email to the recipient. Is there something missing or is it the server I am using that isn't sending the email?

    #3 - In the code in the original post at the bottom there is the link that says Back to the Article with this code:
    <td width="480" align="center"><a href=\"$urltosend\">Back to the Article</a></td>

    When i clicked this link, it did not work properly. Can you tell me what is wrong?
     
    lasvegascom, Jan 24, 2006 IP