larissahn Posted June 13, 2009 Share Posted June 13, 2009 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:leapinglangoor@yahoo.co.in\">leapinglangoor</a>"); print ("</font></div>"); print ("</div>"); } ?>Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/162057-solved-tell-a-friend-script/ Share on other sites More sharing options...
Maq Posted June 13, 2009 Share Posted June 13, 2009 Try echoing all the variables out to see if they are successfully being assigned. Quote Link to comment https://forums.phpfreaks.com/topic/162057-solved-tell-a-friend-script/#findComment-855118 Share on other sites More sharing options...
.josh Posted June 13, 2009 Share Posted June 13, 2009 you use variables in $body before you actually assign anything to them. Quote Link to comment https://forums.phpfreaks.com/topic/162057-solved-tell-a-friend-script/#findComment-855217 Share on other sites More sharing options...
larissahn Posted June 13, 2009 Author Share Posted June 13, 2009 I should REQUEST them first then? Quote Link to comment https://forums.phpfreaks.com/topic/162057-solved-tell-a-friend-script/#findComment-855220 Share on other sites More sharing options...
.josh Posted June 13, 2009 Share Posted June 13, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/162057-solved-tell-a-friend-script/#findComment-855222 Share on other sites More sharing options...
MikeDXUNL Posted June 13, 2009 Share Posted June 13, 2009 Try putting the $body after: $message = $_POST["message"]; Quote Link to comment https://forums.phpfreaks.com/topic/162057-solved-tell-a-friend-script/#findComment-855224 Share on other sites More sharing options...
larissahn Posted June 14, 2009 Author Share Posted June 14, 2009 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"; Quote Link to comment https://forums.phpfreaks.com/topic/162057-solved-tell-a-friend-script/#findComment-855433 Share on other sites More sharing options...
MikeDXUNL Posted June 17, 2009 Share Posted June 17, 2009 You reset the $subject variable. You have $subject = $the_subject delete that line and try again. Quote Link to comment https://forums.phpfreaks.com/topic/162057-solved-tell-a-friend-script/#findComment-858294 Share on other sites More sharing options...
larissahn Posted June 18, 2009 Author Share Posted June 18, 2009 thanks! Quote Link to comment https://forums.phpfreaks.com/topic/162057-solved-tell-a-friend-script/#findComment-858564 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.