Jump to content

Recommended Posts

Hi,

 

I have written an email form but I can its not working properly I keep getting errors, the latest being,

Parse error: syntax error, unexpected T_STRING in D:\Inetpub\vhost\myroho.com\httpdocs\emailform.php on line 49

 

The form is,

 

<!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>
</head>

<body>
<form id="form1" name="form1" method="post" action="emailform.php">
  <label>Send to</label>
  <input type="text" name="Email" id="Email" />
  <p>
    <label>From
    <input type="text" name="From" id="From" />
    </label>
  </p>
  <p>
    <label></label><label>Send
    <input type="submit" name="Send" id="Send" value="Submit" />
    </label>
  </p>
  <p>  </p>
</form>
<p>

<?php

mysql_connect("localhost","adsffdser","clfdsfdsd"); 

mysql_select_db("real") or die("Unable to select database");

$art = $_GET['id'];
$sql = "SELECT * FROM items WHERE id=$art";

$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if($num_rows == 0) {
echo "There has been a problem with your request please try again.";
} else {
while($row = mysql_fetch_array($result)) {
$Title = $row['Title'];

//Check whether the submission is made
if(isset($hidSubmit)){

//Declarate the necessary variables
$mail_to=$Email;
$mail_from=$From;
$mail_sub=Please read this;
$mail_mesg=You have been recomended to read the article $Title on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it.;

//Check for success/failure of delivery 
if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from"))
echo "<span class='textred'>E-mail has been sent successfully you can now send another email or close the window</span>";
else
echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
}
?> </p>
</body>
</html>

 

Does anyone know why this form won't work?

 

All help is appriciated,

Cheers

Colin

Link to comment
https://forums.phpfreaks.com/topic/70945-help-with-email-form/
Share on other sites

also he is missing close brackets

 

 


<?php

mysql_connect("localhost","adsffdser","clfdsfdsd"); 

mysql_select_db("real") or die("Unable to select database");

$art = $_GET['id'];
$sql = "SELECT * FROM items WHERE id=$art";

$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if($num_rows == 0) {
echo "There has been a problem with your request please try again.";
} else {
while($row = mysql_fetch_array($result)) {
$Title = $row['Title'];

//Check whether the submission is made
if(isset($hidSubmit)){

//Declarate the necessary variables
$mail_to=$Email;
$mail_from=$From;
$mail_sub=Please read this;
$mail_mesg=You have been recomended to read the article $Title on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it.;

//Check for success/failure of delivery 
if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from"))
echo "<span class='textred'>E-mail has been sent successfully you can now send another email or close the window</span>";
else
echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
}
}
}

?>

 

also shoould have quotes around your messages

 

<?php
mail_sub="Please read this";
$mail_mesg= echo"You have been recomended to read the article";echo $Title;echo "on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it."; ?>

Link to comment
https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356644
Share on other sites

Hi I made those changes but its still coming up with the same error,

 

Parse error: syntax error, unexpected T_STRING in D:\Inetpub\vhost\myroho.com\httpdocs\emailform.php on line 49

 

Could it have anything to do with the form being included in the same page, I'm still new to php and not sure what to do.

 

Thanks for the help so far,

Colin

Link to comment
https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356704
Share on other sites

please repost your updated code. thanks

 

i know you did but i was confusing myself between braces and bracket

 

i didn't even know they are called braces. i worked with British developers for a number of years where i learned to call them "curly brackets". doh!

Link to comment
https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356730
Share on other sites

Hi,

 

This is the updated form,

 

<!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>
</head>

<body>
<form name="frmsendmail" method="post" action="emailform.php" onSubmit="return ValidationForm()">
  <label>Send to</label>
  <input type="text" name="Email" id="Email" />
  <p>
    <label>From
    <input type="text" name="From" id="From" />
    </label>
  </p>
  <p>
    <label></label><label>Send
    <input type="submit" name="Send" id="Send" value="Submit" />
    </label>
  </p>
  <p>  </p>
</form>
<p>

<?php

mysql_connect("localhost","rere","rere"); 

mysql_select_db("real") or die("Unable to select database");

$art = $_GET['id'];
$sql = "SELECT * FROM items WHERE id=$art";

$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if($num_rows == 0) {
echo "There has been a problem with your request please try again.";
} else {
while($row = mysql_fetch_array($result)) {
$Title = $row['Title'];

//Check whether the submission is made
if(isset($hidSubmit)){

//Declarate the necessary variables
$mail_to=$Email;
$mail_from=$From;
$mail_sub="Please read this";
$mail_mesg= echo"You have been recomended to read the article";echo $Title;echo "on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it.";

//Check for success/failure of delivery 
if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from"))
echo "<span class='textred'>E-mail has been sent successfully you can now send another email or close the window</span>";
else
echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
}
}
}

?> </p>
</body>
</html>

 

Cheers

Colin

Link to comment
https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356741
Share on other sites

$mail_mesg is invalid syntax, should be more like:

 

$mail_mesg= "You have been recomended to read the article $Title on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it.";

 

also, your href isn't valid without http://, and you should quote your URLs, so this is better:

 

$mail_mesg= "You have been recomended to read the article $Title on www.myroho.com click <a href='http://www.myroho.com/more.php?id=$art'>here</a> to read it.";

 

Link to comment
https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356745
Share on other sites

Hi,

 

I made the changes so it now looks like this,

 

<!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>
</head>

<body>
<form name="frmsendmail" method="post" action="emailform.php" onSubmit="return ValidationForm()">
  <label>Send to</label>
  <input type="text" name="Email" id="Email" />
  <p>
    <label>From
    <input type="text" name="From" id="From" />
    </label>
  </p>
  <p>
    <label></label><label>Send
    <input type="submit" name="Send" id="Send" value="Submit" />
    </label>
  </p>
  <p>  </p>
</form>
<p>

<?php

mysql_connect("localhost","arerteer","crreord"); 

mysql_select_db("real") or die("Unable to select database");

$art = $_GET['id'];
$sql = "SELECT * FROM items WHERE id=$art";

$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if($num_rows == 0) {
echo "There has been a problem with your request please try again.";
} else {
while($row = mysql_fetch_array($result)) {
$Title = $row['Title'];

//Check whether the submission is made
if(isset($hidSubmit)){

//Declarate the necessary variables
$mail_to=$Email;
$mail_from=$From;
$mail_sub="Please read this";
$mail_mesg= "You have been recomended to read the article $Title on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it.";

//Check for success/failure of delivery 
if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from"))
echo "<span class='textred'>E-mail has been sent successfully you can now send another email or close the window</span>";
else
echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
}
}
}

?> </p>
</body>
</html>

 

It gets further now because it actually shows the form but when I go to send it it gives me the error,

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Inetpub\vhost\myroho.com\httpdocs\emailform.php on line 36

There has been a problem with your request please try again.

 

Any ideas why,

Thanks

Colin

Link to comment
https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356751
Share on other sites

Hi, thanks for the reply,

 

I changed the php to this,

 

<?php

$conn=mysql_connect("localhost","adder","clifford");


mysql_select_db("real",$conn) or die("Unable to select database");

if( !isset($_GET['id']) ) exit("Nothing Selected"); // error capture
$art = (int)$_GET['id']; //clean 

$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if($num_rows == 0) {
echo "There has been a problem with your request please try again.";
} else {
while($row = mysql_fetch_assoc($result)) {
$Title = $row['Title'];

//Check whether the submission is made
if(isset($hidSubmit)){

//Declarate the necessary variables
$mail_to=$Email;
$mail_from=$From;
$mail_sub="Please read this";
$mail_mesg= "You have been recomended to read the article $Title on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it.";

//Check for success/failure of delivery 
if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from"))
echo "<span class='textred'>E-mail has been sent successfully you can now send another email or close the window</span>";
else
echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
}
}
}

?>

 

But I now get the error,

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Inetpub\vhost\myroho.com\httpdocs\emailform.php on line 37

There has been a problem with your request please try again.

 

and when I go to send the email it says,

 

Nothing Selected

 

Cheers

Colin

Link to comment
https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356791
Share on other sites

true you seam to of taken it out

 

mysql_select_db("real",$conn) or die("Unable to select database");

if( !isset($_GET['id']) ) exit("Nothing Selected"); // error capture
$art = (int)$_GET['id']; //clean

$sql = "SELECT * FROM items WHERE id=$art"; //ADD BACK IN

 

as for the email not working, your link to the email MUST have ?id=number or ie will fails hence the error capture

Link to comment
https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356795
Share on other sites

Thanks for the help, I changed that and the main error went. As for the second one about 'Nothing Selected', when the form comes up it has the ?id=number but I think when you submit the form it looses it before it is procesed. Any ideas how I could keep it?

 

Thanks,

Colin

Link to comment
https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356802
Share on other sites

Hi,

I made the changes but its still not working,

 

My full code now is,

<!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>
</head>

<body>
<?php
echo '<form name="frmsendmail" method="post" action="emailform.php?ID='.$_GET['ID'].'" onSubmit="return ValidationForm()">';
?>

  <label>Send to</label>
  <p>
    <input type="text" name="Email" id="Email" />
  </p>
  <p>
    <label>From
    <input type="text" name="From" id="From" />
    </label>
  </p>
  <p>
    <label></label><label>Send
    <input type="submit" name="Send" id="Send" value="Submit" />
    </label>
  </p>
  <p>  </p>
</form>
<p>

<?php

$conn=mysql_connect("localhost","adder","clifford"); 

mysql_select_db("real",$conn) or die("Unable to select database");

if( !isset($_GET['id']) ) exit("Nothing Selected"); // error capture
$art = (int)$_GET['id']; //clean 
$sql = "SELECT * FROM items WHERE id=$art";

$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if($num_rows == 0) {
echo "There has been a problem with your request please try again.";
} else {
while($row = mysql_fetch_assoc($result)) {
$Title = $row['Title'];

//Check whether the submission is made
if(isset($hidSubmit)){

//Declarate the necessary variables
$mail_to=$Email;
$mail_from=$From;
$mail_sub="Please read this";
$mail_mesg= "You have been recomended to read the article $Title on www.myroho.com click <a href=www.myroho.com/more.php?id=$art>here</a> to read it.";

//Check for success/failure of delivery 
if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from"))
echo "<span class='textred'>E-mail has been sent successfully you can now send another email or close the window</span>";
else
echo "<span class='textred'>Failed to send the E-mail from $mail_sub to $mail_to</span>";
}
}
}

?> </p>
</body>
</html>

 

Any ideas why this isn't working?

 

Thanks for all the help so far,

Colin

Link to comment
https://forums.phpfreaks.com/topic/70945-help-with-email-form/#findComment-356822
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.