steviez Posted January 30, 2007 Share Posted January 30, 2007 Hi,I have a form on my site for users to email links to friends, i want a confirmation message to apear after they have submited the form, somthing like "Your Message(s) Have Been Sent!"I have included my code for you to look at so you understand better.[code]<?phpob_start();include("connect.php");if(!$UsErId){ $redirect = $SITEURL."login.php"; header("Location:$redirect");} if($user_id != ''){ $msgDisplay = "This profile is owsome";}else if($audio_id != ''){ $msgDisplay = "This music is owsome";}else{ $msgDisplay = "Invitation to join ".$SITENAME;}if($action_send){ $user = select_user_from_audio($UsErId); $ex_recipients = explode(",",$recipients); $count_recipients = count($ex_recipients); if($user_id) { $msg_link = "<a href=".$SITEURL."profile.php?user_id=$user_id&ch=u&fla=profile target=_blank>Here</a>"; $msg_subject = $user[username]." has sent one profile to view."; $mail_msg = "hello ".$msg_subject." ".$message." Click ".$msg_link." to view the Profile. Thanks for using ".$SITENAME."! Regards, The ".$SITENAME." Team "; if(($count_recipients > 0) && ($ex_recipients[0] != '')) { for($i=0;$i<$count_recipients;$i++) { mail($ex_recipients[0],$msg_subject,$mail_msg); } } else { $ERROR = "Please enter atleast one Email address"; } } else if($audio_id) { if($audio_id == '') { $audio_id = 1; } $msgDisplay = "This music is owsome"; $msg_link = "<a href=".$SITEURL."audios/listen.php?ch=v&id=".$audio_id." target=_blank>Here</a>"; $msg_subject = $user[username]." has sent you some music to listen to."; $mail_msg = "hello ".$msg_subject." ".$message." Click ".$msg_link." listen to the music. Thanks for using ".$SITENAME."! Regards, The ".$SITENAME." Team "; if(($count_recipients > 0) && ($ex_recipients[0] != '')) { for($i=0;$i<$count_recipients;$i++) { mail($ex_recipients[0],$msg_subject,$mail_msg); } } else { $ERROR = "Please enter atleast one Email address"; } } else { $ref = "ref".$timestring; $msgDisplay = "Have you heard about Music4Play.com? I love this site."; $msg_link = "<a href=".$SITEURL."createacc.php?ch=cr&ref=".$ref."&inv=accept target=_blank>Here</a>"; $msg_subject = $user[username]." has send invitation to join ".$SITENAME; $mail_msg = "hello ".$SITENAME." is a new site for sharing and hosting your music. I have been using ".$SITENAME." to share my work with others. I would like to add you to the list of people I may share my work with. ".$message." Click ".$msg_link." to signup. Thanks for using ".$SITENAME."! Regards, The ".$SITENAME." Team "; if(($count_recipients > 0) && ($ex_recipients[0] != '')) { $myDate = date("Y-m-d"); for($i=0;$i<$count_recipients;$i++) { mail($ex_recipients[0],$msg_subject,$mail_msg); $select_email = "select id from friends where email_id = '$ex_recipients[0]' and user_id = '$UsErId' and deleted = 'NO'"; $result_email = mysql_query($select_email); $num_email = mysql_num_rows($result_email); if($num_email < 1) { $insert_mail = "insert into friends (user_id,email_id,friend_date) values('$UsErId','$ex_recipients[0]','$myDate')"; $result_mail = mysql_query($insert_mail); } } } else { $ERROR = "Please enter atleast one Email address"; } } }$SUCCESS = "Your message(s) were sent!"; ?><link href="../css/main.css" rel="stylesheet" type="text/css"><script type="text/javascript"><!-- function fillAll(){ window.resizeTo(560,490); //resize the window to the correct size window.focus();}var remote;function launch_share(n,u,w,h) { remote=window.open(u,n,'width='+w+',height='+h+',resizable=yes,scrollbars=yes,status=0'); remote.opener = self; if (remote != null) { if (remote.opener == null ) remote.opener = self; } remote.focus();}function signup(){ window.location = "/small_signup?next_url=" + escape(window.location)}// --></script><body onLoad="fillAll();" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"><br><table align="center" width="76%" class="page_content_frame"> <?php if($ERROR) { ?> <tr> <td align="center"><br><font color="#FF0000"><?php echo $ERROR; ?></font><br></td> </tr> <?php } ?> <tr> <td> <table width="496" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td width="334" valign="top"> <form id="ShareForm" name="ShareForm" method="POST" action="#"> <? if($user_id) { ?> <input type="hidden" name="user_id" value="<?php echo $user_id ?>"> <? } if($audio_id) { ?> <input type="hidden" name="audio_id" value="<?php echo $audio_id ?>"> <? } ?> <strong> <nobr> <? echo $lang['Email_To']; ?> :</nobr> </strong> <br /> <? echo $lang['enter_email_addr']; ?> .<br /> <textarea id="recipients" name="recipients" rows="8" cols="32" value="" size="60" maxlength="255" onChange="addressframe.updateCheckboxes();" ></textarea> <br /> <strong><nobr> <? echo $lang['Add_a_personal_message']; ?> :</nobr> </strong> ( <? echo $lang['optional']; ?> )<br> <textarea wrap="virtual" name="message" rows="3" cols="32"><? echo $msgDisplay ?></textarea> <br /> <input type="submit" name="action_send" value="Send"> </form> </table> </td> </tr></table></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/36377-success-message/ Share on other sites More sharing options...
Ninjakreborn Posted January 30, 2007 Share Posted January 30, 2007 You really could clean that up a bit.Conventionally.it is just done with [code]<?phpif (mail($to, $subject, $message, $headers)) { echo "success message here";}else { echo "Failure message here";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/36377-success-message/#findComment-173080 Share on other sites More sharing options...
Rottingham Posted January 30, 2007 Share Posted January 30, 2007 Or, the more eye-appealing way is to make an actual HTML template of the error or success message, and either echo that out, or redirect the browser to the stored html file.[code]<?php$success = "<img src='yourdomain.com/images/success.jpg' align='left'> <font color='red' size='2'>Your message(s) have been sent!<br></font>";$failure= "<img src='yourdomain.com/images/failure.jpg' align='left'> <font color='red' size='2'>There was an error sending your message.<br></font>";if (mail($to, $subject, $message, $headers)) { echo $success;}else { echo $failure;}?>[/code]Or[code]<?phpif (mail($to, $subject, $message, $headers)) { echo "window.location='forms/success.html'";}else { echo "window.location='forms/failure.html";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/36377-success-message/#findComment-173107 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.