Dynadot โ€” .com Registration $8.99

Send a friend php code help

Spaceship Spaceship
Watch

lasvegascom

Established Member
Impact
2
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">ย </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">ย </td>
</tr>
<tr>
<td width="60">ย </td>
<td width="480" align="center"><a href=\"$urltosend\">Back to the Article</a></td>
<td width="60">ย </td>
</tr>
</table>
</body>
</html>
<?php
}
?>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
<td width="480" class="txt">Thanks for recommeding our article. An e-mail has been sent to <b><?=$recipemail?></b>.<br><br></td>
 
0
•••
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.
 
0
•••
Code:
you were previously browsing</a>?</p>";
}
} else {
?>
<html>
<head>

illegal especially since it is like this:

Code:
</html>
<?php
}
?>

im pretty sure that wont work because the server will parse the "}" as a seperate entity. and therefore the "else" statement was never terminated.

what you have to do is change the else part to look like this:

Code:
} else {
echo('
<html>
#HTML CODE SKIPPED FOR BREVITY
</tr>
</table>
</body>
</html>
');
}
?>

basically you're echoing the whole html page.
 
0
•••
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>
 
0
•••
I dont quite understand you but :
is this what you want?

PHP:
 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>";
}

change to:
PHP:
mail($recipemail,$subject,$staticmsg,$headers);
 
0
•••
oh wait i think i know now...

put all ur html code. and then in the exact part where u want to echo whether or not it was successful, put in the mailing php code as well as the echo "successful etc etc" part.

does that work?
 
0
•••
nasaboy007 said:
oh wait i think i know now...

put all ur html code. and then in the exact part where u want to echo whether or not it was successful, put in the mailing php code as well as the echo "successful etc etc" part.

does that work?

can you show mean what you mean by that by adjusting the code i have above? I don't know php at all.

In the end what i really want is that this page shows the success or failure message within my html code so that it fits the style of my website.

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">ย </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">ย </td>
</tr>
<tr>
<td width="60">ย </td>
<td width="480" align="center"><a href=\"$urltosend\">Back to the Article</a></td>
<td width="60">ย </td>
</tr>
</table>
</body>
</html>
 
0
•••
Code:
<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>
[B]</head>
<body>[/B]
<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">ย </td>
<td width="480" class="txt">
<?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 = [B]"Hi" . $recipname . "! \n Your Colleague" . $sendername . "has recommended that you read this article from domain name with the following message: \n" . $custmessage . "\n";[/B]
#Gotta concatenate otherwise previous ones will be overwritten
[B]$staticmsg .= "$urltosend";
$staticmsg .= "SITE PROMOTION TEXT AREA";
$staticmsg .= "SITE PROMOTION TEXT AREA";
$staticmsg .= "SITE PROMOTION TEXT AREA";[/B]

$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 'Thanks for recommeding our article. [B]An e-mail has been sent to <b>' . $recipemail . '</b>.';[/B]
} else {
echo 'Your message could not be sent at this time. [B]Go back to the <a href=\"' . $urltosend . '\">page you were previously browsing</a>';[/B]
}
?>

<br><br></td>
<td width="60">ย </td>
</tr>
<tr>
<td width="60">ย </td>
<td width="480" align="center">[B]<a href="<? echo($urltosend); ?>">[/B]Back to the Article</a></td>
<td width="60">ย </td>
</tr>
</table>
</body>
</html>

ok I boldfaced what i changed and some general syntax errors that you had and i corrected. look those over. and also, notice how all the php code is INSIDE the <body> tags of the html.

tell if this works.

EDIT: I JUST REALIZED SOMETHING
The reason it wasn't working might have been because... >_< you hadn't closed your head tags and opened the body tag X_X

but i had caught that in my version so u can jsut use mine.
 
0
•••
ok. now there are two problems.

1. no email is sent.
2. the back to the article link goes nowhere.
 
0
•••
Its most probably a problem with the posted variables. Make sure the previous page contains <form method='post' action='whatever.php'>
 
0
•••
This is what I have exactly. I want the form and confirmation page to be a 600x500 pop up. And a email is sent to the friend with one of my email address' bcc'd.

Link on Article pages:
Code:
<a href="tellafriend.php?page=<?=$page;?> class="a_link">Email a Colleague</a>

Form Page:
Code:
<?php
$page = basename($_SERVER['SCRIPT_FILENAME']);
$page = str_replace('.php','',$page);
?>
<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>
<script type="text/javascript" language="JavaScript" src="scripts/email.js"></script>
<script language="JavaScript">
<!--
window.focus();
// -->
</script>
</HEAD>

<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">ย </td>
        		<td width="480" class="header_orng">Send this article to a colleague</td>
		    <td width="60">ย </td>
			</tr>
      		<tr>
			<td class="txt">
      		  <td width="480" bgcolor="#CCCCCC"><img src="images/spacer.gif" width="1" height="1"></td>
				<td class="txt">
   		  </tr>
      		 <tr>
      		<td width="6"><img src="images/spacer.gif" width="3" height="1"></td>
			</tr>
<tr>
  <td width="60" class="txt">  
   		      <td class="txt"><br>

             <form action="tell.php" method="post">
			 <input type="hidden" name="urlsent" id="urlsent" value="<?=$complete_url;?>">
<table width="480" border="0" cellpadding="1" cellspacing="0">
               				<tr>
                      <td width="40%" height="25" class="txt"><strong>Colleague's Email Address: </strong></td>
                      <td width="60%" class="txt"><input type="text" name="recipemail" id="recipemail"></td>
                    </tr>
					<tr>
                      <td width="40%" height="25" class="txt"><strong>Colleague's Name: </strong></td>
                      <td width="60%" class="txt"><input type="text" name="recipname" id="recipname"></td>
                    </tr>
					<tr>
                      <td width="40%" height="25" class="txt"><strong>Your Name: </strong></td>
                      <td width="60%" class="txt"><input type="text" name="sendername" id="sendername"></td>
                    </tr>
                  		<tr>
                      <td width="40%" height="25" class="txt"><strong>Your Email Address: </strong></td>
                      <td width="60%" class="txt"><input type="text" name="senderemail" id="senderemail"></td>
                    </tr>		
                  	<tr> 
                  <td height="30" class="txt"> 
                    <p><strong> Your Message: </strong>                    </p>                  </td>
                  <td class="txt"> 
                    <p> 
                      <textarea cols="40" rows="5" name="message"></textarea>
                    </p>                  </td>
                </tr>
                <tr> 
				     <td>ย </td>
                  <td height="30" colspan="2" class="txt"><input type="submit" name="submit" id="submit" value="Send">
                    <input type="reset" value="Reset" name="reset" id="reset"></td>
                </tr>
              </table>
            </form>
</table>
</body>
</html>

Confirmation Page:
Code:
<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>
<script type="text/javascript" language="JavaScript" src="scripts/email.js"></script>
</head>
<body>
<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">ย </td>
<td width="480" class="txt">
<?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 . "\n";
#Gotta concatenate otherwise previous ones will be overwritten
$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 '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">ย </td>
</tr>
<tr>
<td width="60">ย </td>
<td width="480" align="center"><a href="<? echo($urltosend); ?>">Back to the Article</a></td>
<td width="60">ย </td>
</tr>
</table>
</body>
</html>
 
0
•••
mind posting the names of the files? bcuz if theres an error (like the filename isnt tell.php or something) we need that too.
 
0
•••
article name = cost.htm
Form Page name = tellafriend.php
Confirmation Page Name = tell.php
 
0
•••
try making $header end with the \r\n bcuz i think they need to be at the end of the header.

also, did the email work before? because if it didnt, i wud advise u to check if ur host suports php mail.
 
0
•••
the $header does end with \r\n unless I do not understand what you mean by that. This is what I have:
$headers = "From: My Domain \r\n";

The email never worked for me so it may be my host.
 
0
•••
no u dont have that for headers, you have this:
$headers = "From: My Domain \r\n";
$headers .= "Reply-To:" . $senderemail;

which is the same as this

$headers = "From: My Domain \r\n Reply-To:" . $senderemail;

so now u see it doesnt end in \r\n.

And since the email didnt work from the beginning, I would advise u to contact ur host and find out if php email is supported.
 
0
•••
thanks i will try that new way and talk to my webhost.

thanks so much for all the help.
 
0
•••
Try this:

PHP:
<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>
<script type="text/javascript" language="JavaScript" src="scripts/email.js"></script>
</head>

<body>

<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">ย </td>
  <td width="480" class="txt">
<?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."\n";
  #Gotta concatenate otherwise previous ones will be overwritten
  $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."\r\n";

  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">ย </td>
</tr>
<tr>
  <td width="60">ย </td>
  <td width="480" align="center"><a href="<?php echo $urltosend; ?>">Back to the Article</a></td>
  <td width="60">ย </td>
</tr>
</table>

</body>
</html>
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back