graphxdiva
asked on
Script to send email not working correctly..
I have a page that I am going to use to regenerate a forgotten password, store it to the db and then send it to a page that emails it to the user. For some reason my email page isn't working. I am getting an error "Parse error: parse error, unexpected T_ECHO in /home/content/t/f/d/tfd200 7/html/mag /emailpw.p hp on line 48" which is the line in the mail() script - $message = 'Your Username is: '.echo $row_rs_user['username']." \r\n".'You r Password is: '. echo $newpw;
I know all the sessions are set because i have echoed them in the body and see that they are correct as well as the record set information. What am I doing wrong? I'm sure its just a missed () or something simple but my brain is just fried from looking at it. Here is the entire page code..
Thanks for any help!
<?php require_once('Connections/ MagazineDB .php');
session_start();
?>
<?php
if (!function_exists("GetSQLV alueString ")) {
function GetSQLValueString($theValu e, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea l_escape_s tring") ? mysql_real_escape_string($ theValue) : mysql_escape_string($theVa lue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$newpw = $_SESSION['nwpw'];
$user = $_SESSION['username'];
$colname_rs_user = "-1";
if (isset($_SESSION['username '])) {
$colname_rs_user = $_SESSION['username'];
}
mysql_select_db($database_ MagazineDB , $MagazineDB);
$query_rs_user = sprintf("SELECT * FROM users WHERE username = %s", GetSQLValueString($colname _rs_user, "text"));
$rs_user = mysql_query($query_rs_user , $MagazineDB) or die(mysql_error());
$row_rs_user = mysql_fetch_assoc($rs_user );
$totalRows_rs_user = mysql_num_rows($rs_user);
//Start Email
$to = $row_rs_user['email_addres s'];
$subject = 'Your Login Information';
$message = 'Your Username is: '.echo $row_rs_user['username']." \r\n".'You r Password is: '. echo $newpw;
$headers = 'From: craig@topfueldesign.com' . "\r\n" .
'Reply-To: craig@topfueldesign.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
//End Email
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<meta http-equiv="Refresh" content="8;URL=index.php" />
</head>
<body>
<div id="page">
<div id="page_content">
<p align="center">Your New Password Has Been Sent To <?php echo $row_rs_user['email_addres s'] ?>.<br />
<a href="index.php">Redirecti ng..</a>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($rs_user );
?>
I know all the sessions are set because i have echoed them in the body and see that they are correct as well as the record set information. What am I doing wrong? I'm sure its just a missed () or something simple but my brain is just fried from looking at it. Here is the entire page code..
Thanks for any help!
<?php require_once('Connections/
session_start();
?>
<?php
if (!function_exists("GetSQLV
function GetSQLValueString($theValu
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_rea
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$newpw = $_SESSION['nwpw'];
$user = $_SESSION['username'];
$colname_rs_user = "-1";
if (isset($_SESSION['username
$colname_rs_user = $_SESSION['username'];
}
mysql_select_db($database_
$query_rs_user = sprintf("SELECT * FROM users WHERE username = %s", GetSQLValueString($colname
$rs_user = mysql_query($query_rs_user
$row_rs_user = mysql_fetch_assoc($rs_user
$totalRows_rs_user = mysql_num_rows($rs_user);
//Start Email
$to = $row_rs_user['email_addres
$subject = 'Your Login Information';
$message = 'Your Username is: '.echo $row_rs_user['username']."
$headers = 'From: craig@topfueldesign.com' . "\r\n" .
'Reply-To: craig@topfueldesign.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
//End Email
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<meta http-equiv="Refresh" content="8;URL=index.php" />
</head>
<body>
<div id="page">
<div id="page_content">
<p align="center">Your New Password Has Been Sent To <?php echo $row_rs_user['email_addres
<a href="index.php">Redirecti
</div>
</div>
</body>
</html>
<?php
mysql_free_result($rs_user
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this, just a syntax error
<?php require_once('Connections/MagazineDB.php');
session_start();
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$newpw = $_SESSION['nwpw'];
$user = $_SESSION['username'];
$colname_rs_user = "-1";
if (isset($_SESSION['username'])) {
$colname_rs_user = $_SESSION['username'];
}
mysql_select_db($database_MagazineDB, $MagazineDB);
$query_rs_user = sprintf("SELECT * FROM users WHERE username = %s", GetSQLValueString($colname_rs_user, "text"));
$rs_user = mysql_query($query_rs_user, $MagazineDB) or die(mysql_error());
$row_rs_user = mysql_fetch_assoc($rs_user);
$totalRows_rs_user = mysql_num_rows($rs_user);
//Start Email
$to = $row_rs_user['email_address'];
$subject = 'Your Login Information';
$message = 'Your Username is: ' . $row_rs_user['username'] . '\r\n' . 'Your Password is: ' . $newpw;
$headers = 'From: craig@topfueldesign.com' . "\r\n" .
'Reply-To: craig@topfueldesign.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
//End Email
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<meta http-equiv="Refresh" content="8;URL=index.php" />
</head>
<body>
<div id="page">
<div id="page_content">
<p align="center">Your New Password Has Been Sent To <?php echo $row_rs_user['email_address'] ?>.<br />
<a href="index.php">Redirecting..</a>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($rs_user);
?>
Open in new window