Jump to content

[SOLVED] Tell a friend script


larissahn

Recommended Posts

hi, I have this tell a friend php script. it works, it does send the email, but without any of the fields, like subject, friend's name, message.

here is the code:

<?php 

$site_name = "www.utilaecology.org"; 
$subject = "Tell a friend"; 
$body = "Hello,\r\nYour friend $name ($email) has recommended that you see our website $site_name. He has also sent this message along with the recommendation:\r\n" . $message . "\r\n Thank you,\r\n-The webmaster"; 

if($_POST["send"] == "true") { 
    $to = $_POST["to"]; 
    $name = $_POST["name"]; 
    $email = $_POST["email"]; 
    $message = $_POST["message"]; 
    if (($name == "") OR ($email == "") OR ($message == "")) { 
        print ("<div id=\"sectionContent\">"); 
        print ("<font color=\"red\">One of the fields was left blank. Please put something in all fields.</font><br><br>"); 
        print ("</div><br>"); 
        email_form(); 
    }elseif(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $email)) { 
        $recipient = $to; 
        $subject = $the_subject; 
        $additional_headers = ("From: $email\n"); 
        if(mail($recipient, $subject, $body, $additional_headers)) { 
            print ("<div id=\"sectionContent\">"); 
            print ("<font color=\"red\">Tell a friend script mailed your friend at $to about $site_name successfully.<br>Thank you.</font><br><br>"); 
            print ("</div><br>"); 
        }else{ 
            print ("<div id=\"sectionContent\">"); 
            print ("<font color=\"red\">Uh-Oh! Something went wrong with the script! Please try again.</font><br><br>"); 
            print ("</div><br>"); 
            $send = "false"; 
            email_form(); 
        } 
    }else{ 
        print ("<div id=\"sectionContent\">"); 
        print ("<font color=\"red\">That email address does not appear to be valid. Please try again.</font><br><br>"); 
        print ("</div><br>"); 
        $send = "false"; 
        email_form(); 
    } 

}else{ 
    print ("<div id=\"sectionContent\">"); 
    print ("<p align=\"center\"><font size=\"62\">Tell a friend</font></p>"); 
    print ("</div><br>"); 
    email_form(); 
} 

function email_form(){ 
    global $subject_array, $recipient_array, $this_script, $PHP_SELF; 

    print ("<div id=\"sectionContent\">"); 
    print ("<form METHOD=POST action=\"$PHP_SELF\">\n"); 
    print ("<table align=\"center\" border=\"1\" bordercolor=\"E0E8EF\"><tr><td align=\"left\">"); 
    print ("To:<br>\n"); 
    print ("</td><td>"); 
    print ("<input type=\"text\" name=\"to\" size=\"30\"><br>\n"); 
    print ("</td></tr><tr><td align=\"left\">"); 
    print ("Name:<br>\n"); 
    print ("</td><td>"); 
    print ("<input type=\"text\" name=\"name\"><br>\n"); 
    print ("</td></tr><tr><td align=\"left\">"); 
    print ("Your Email Address:<br>\n"); 
    print ("</td><td>"); 
    print ("<input type=\"text\" name=\"email\" size=\"40\"><br>\n"); 
    print ("</td></tr><tr><td align=\"left\">"); 
    print ("Your Message:<br>\n"); 
    print ("</td><td>"); 
    print ("<textarea cols=\"50\" rows=\"5\" name=\"message\"></textarea><br>\n"); 
    print ("</td></tr><tr><td>"); 
    print ("</td>"); 
    print ("<td>"); 
    print ("<input type=\"hidden\" name=\"send\" value=\"true\">\n"); 
    print ("<input type=\"submit\" value=\"Submit\"> \n"); 
    print ("<input type=\"reset\" value=\"Reset Fields\">\n"); 
    print ("</td></tr></table>"); 
    print ("</form>\n"); 
    print ("<div align=\"center\"><font size=\"1\" color=\"888888\">"); 
    print ("script by <a href=\"mailto:[email protected]\">leapinglangoor</a>"); 
    print ("</font></div>"); 
    print ("</div>"); 
} 
?>Thanks!

Link to comment
https://forums.phpfreaks.com/topic/162057-solved-tell-a-friend-script/
Share on other sites

no, you should assign the $_POST'ed values to the variables before you try to use them in your $body string.  Either move those variable assignments up to before your $body assignment, or else move your $body assignment down lower in your code, after those vars are assigned.

ok, thank you, Mike. I moved $body where you said. now the problem I have is I get a "no subject" on the email I received. I tried moving $subject, too, but it didn't work.

 

if($_POST["send"] == "true") { 
    $to = $_POST["to"]; 
    $name = $_POST["name"]; 
    $email = $_POST["email"]; 
    $message = $_POST["message"]; 

$subject = "Tell a friend"; 
$body = "Hello,\r\nYour friend $name ($email) has recommended that you see our website $site_name. He has also sent this message along with the recommendation:\r\n" . $message . "\r\n Thank you,\r\n-The webmaster"; 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.