8 Replies - 1249 Views - Last Post: 06 July 2009 - 06:31 PM Rate Topic: -----

#1 The Rock  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 24-September 07

Email Form Problems!

Posted 06 July 2009 - 09:14 AM

Hello everybody,

I am trying to write an email form in PHP and it's not working out. ANY help would be greatly appreciated!

contact.html:
<!-- DO NOT change ANY of the php sections -->
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />

<form method="POST" action="contact.php">
  <tr>
	<td>FirstName:*</td>
	<td><input type="text" name="FirstName"></td>
  </tr>
  <tr>
	<td>LastName:*</td>
	<td><input type="text" name="LastName"></td>
  </tr>
  <tr>
	<td>Address 1:*</td>
	<td><input type="text" name="Street1"></td>
  </tr>
  <tr>
	<td> Address 2:*</td>
	<td><input type="text" name="Street2"></td>
  </tr>
  <tr>
	<td>City:*</td>
	<td><input type="text" name="City"></td>
  </tr>
  <tr>
	<td>Zip Code:*</td>
	<td><input type="text" name="ZipCode"></td>
  </tr>
  <tr>
	<td>State:*</td>
	<td><input type="text" name="State"></td>
  </tr>
  <tr>
	<td>Day Telephone:*</td>
	<td><input type="text" name="DayTel"></td>
  </tr>
  <tr>
	<td>Night Telephone:*</td>
	<td><input type="text" name="NightTel"></td>
  </tr>
  <tr>
	<td>Email From:*</td>
	<td><input type="text" name="EmailFrom"></td>
  </tr>
  <tr>
	<td>Comments:*</td>
	<td><textarea name="Comments" cols="50"></textarea></td>
  </tr>
  <tr>
	<td><input type="submit" name="submit" value="Send Mail"></td>
  </tr>
  </form>



contact.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>

<!-- Reminder: Add the link for the 'next page' (at the bottom) -->
<!-- Reminder: Change 'YourEmail' to Your real email -->

<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Street1 = $_POST['Street1'];
$Street2 = $_POST['Street2'];
$City = $_POST['City'];
$ZipCode = $_POST['ZipCode'];
$State = $_POST['State'];
$DayTel = $_POST['DayTel'];
$NightTel = $_POST['NightTel'];
$EmailFrom = $_POST['EmailFrom'];
$Comments = $_POST['Comments'];


if (eregi('http:', $Comments)) {
die ("Do NOT try that! ! ");
}
if(!$EmailFrom == "" && (!strstr($EmailFrom,"@") || !strstr($EmailFrom,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($FirstName) || empty($LastName) || empty($Street1) || empty($City) || empty($State) || empty($ZipCode) || empty($DayTel) || empty($NightTel) || empty($Comments)) {
echo "<h2>Use Back - fill in all fields</h2>\n";
die ("Use back! ! ");
}

$todayis = date("l, F j, Y, g:i a");

//$attn = $attn;
$subject = "You have an email from your website";

$Comments = stripcslashes($Comments);

$message = " $todayis [EST] \n
Name: $FirstName $LastName \n
Email: $EmailFrom \n
Address 1: $Street1 \n
Address 2: $Street2 \n
City: $City \n
State: $State \n
Zip Code: $ZipCode \n
Daytime Telephone: $DayTel \n
Nighttime Telephone: $NightTel \n
Comments: $Comments \n
=========================
Additional Info: IP = $ip \n
Browser Info: $httpagent \n
Referral: $httpref \n
";

$from = "From: $EmailFrom\r\n";
$visitor = "$FirstName $LastName";


[b]mail("email@address.com", $subject, $message, $from);[/b]

?>

<p align="center">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $EmailFrom ?> )
<br />
Address 1: <?php echo $Street1 ?>
<br />
Adress 2: <?php echo $Street2 ?>
<br />
City: <?php echo $City ?>
<br />
State: <?php echo $State ?>
<br />
Zip Code: <?php echo $ZipCode ?>
<br />
Daytime Telephone: <?php echo $DayTel ?>
<br />
Nighttime Telephone: <?php echo $NightTel ?>
<br />
Comments:<br />
<?php $notesout = str_replace("\r", "<br/>", $Comments);
echo $notesout; ?>
<br />
<?php echo $ip ?>

<br /><br />
<a href="index.html"> Home Page </a>
</p>

</body>
</html>



Error message:
Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\4524320\html\Site\contact.php on line 75

Line 75 listed with [b]-[/b] in contact.php.



Thank you in advance for any help you can offer me.
The Rock :D

Is This A Good Question/Topic? 0
  • +

Replies To: Email Form Problems!

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Email Form Problems!

Posted 06 July 2009 - 09:30 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 The Rock  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 24-September 07

Re: Email Form Problems!

Posted 06 July 2009 - 09:34 AM

View PostPsychoCoder, on 6 Jul, 2009 - 08:30 AM, said:

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field



PsychoCoder,

If you'll see in my message, the body text, I put the error message into the code format at the bottom of the message. Secondly, the Subject was just to say specifically what problem I was having, specifically with the Email form. And thirdly, I could elaborate on what I intend for the form to do, send the email.

Thanks.
The Rock :D
Was This Post Helpful? 0
  • +
  • -

#4 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: Email Form Problems!

Posted 06 July 2009 - 09:36 AM

[b]mail("email@address.com", $subject, $message, $from);[/b]



Line 75 is this looks like your trying to use BBCode in PHP ...

furthermore if your expecting the function to return a string to print whether or not it sent or not that's not going to work.. you would need to assign the function to a variable and echo a statement after

$emailProgress = mail("email@address.com", $subject, $message, $from);

if ($emailProgress) {
  // email sent echo something
} else {
  // error in sending echo something
}


This post has been edited by RPGonzo: 06 July 2009 - 09:52 AM

Was This Post Helpful? 0
  • +
  • -

#5 The Rock  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 24-September 07

Re: Email Form Problems!

Posted 06 July 2009 - 11:51 AM

View PostRPGonzo, on 6 Jul, 2009 - 08:36 AM, said:

[b]mail("email@address.com", $subject, $message, $from);[/b]



Line 75 is this looks like your trying to use BBCode in PHP ...

furthermore if your expecting the function to return a string to print whether or not it sent or not that's not going to work.. you would need to assign the function to a variable and echo a statement after

$emailProgress = mail("email@address.com", $subject, $message, $from);

if ($emailProgress) {
  // email sent echo something
} else {
  // error in sending echo something
}



RPGonzo,

Thanks for replaying and helping me. I placed the code you provided into the appropriate place:

$emailProgress = mail("email@address.com", $subject, $message, $from);
if ($emailProgress) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactok.html\">";
} else {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contacterror.html\">";
}



But when testing it out I received the following error message:
Use Back - Enter valid e-mail\n"; $badinput = "
Feedback was NOT submitted
\n"; echo $badinput; die ("Go back! ! "); } if(empty($FirstName) || empty($LastName) || empty($Street1) || empty($City) || empty($State) || empty($ZipCode) || empty($DayTel) || empty($NightTel) || empty($Comments)) { echo "
Use Back - fill in all fields
\n"; die ("Use back! ! "); } $todayis = date("l, F j, Y, g:i a"); //$attn = $attn; $subject = "You have an email from your website"; $Comments = stripcslashes($Comments); $message = " $todayis [EST] \n Name: $FirstName $LastName \n Email: $EmailFrom \n Address 1: $Street1 \n Address 2: $Street2 \n City: $City \n State: $State \n Zip Code: $ZipCode \n Daytime Telephone: $DayTel \n Nighttime Telephone: $NightTel \n Comments: $Comments \n ========================= Additional Info: IP = $ip \n Browser Info: $httpagent \n Referral: $httpref \n "; $from = "From: $EmailFrom\r\n"; $visitor = "$FirstName $LastName"; $emailProgress = mail("grott24@unicorncom.net", $subject, $message, $from); if ($emailProgress) { print ""; } else { print ""; } ?>

Date:
Thank You : ( )
Address 1:
Adress 2:
City:
State:
Zip Code:
Daytime Telephone:
Nighttime Telephone:
Comments:
", $Comments); echo $notesout; ?>


Go Back To Home Page



And when I uploaded the files to my sever I received the following error message:
Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\#######\html\Site\contact.php on line 74



Thanks again for helping me.
The Rock :D
Was This Post Helpful? 0
  • +
  • -

#6 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: Email Form Problems!

Posted 06 July 2009 - 12:17 PM

can you paste your current code completely please.

and a quick google on that server response i came up with this ...

Quote

451 - The command has been aborted due to a server error. Not your fault. Maybe let the admin know.


maybe your server is either having issues or the mail command may not be accessible...

and maybe try completely sending the headers ... instead of just $from use

$headers = "From: $from \r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-mailer: mysite.com Server\r\n";

$emailProgress = mail("email@address.com", $subject, $message, $headers);


This post has been edited by RPGonzo: 06 July 2009 - 12:22 PM

Was This Post Helpful? 0
  • +
  • -

#7 The Rock  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 24-September 07

Re: Email Form Problems!

Posted 06 July 2009 - 12:56 PM

RPGonzo,

Here's the full code for the contact.php as I have it now:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>

<!-- Reminder: Add the link for the 'next page' (at the bottom) -->
<!-- Reminder: Change 'YourEmail' to Your real email -->

<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Street1 = $_POST['Street1'];
$Street2 = $_POST['Street2'];
$City = $_POST['City'];
$ZipCode = $_POST['ZipCode'];
$State = $_POST['State'];
$DayTel = $_POST['DayTel'];
$NightTel = $_POST['NightTel'];
$EmailFrom = $_POST['EmailFrom'];
$Comments = $_POST['Comments'];


if (eregi('http:', $Comments)) {
die ("Do NOT try that! ! ");
}
if(!$EmailFrom == "" && (!strstr($EmailFrom,"@") || !strstr($EmailFrom,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($FirstName) || empty($LastName) || empty($Street1) || empty($City) || empty($State) || empty($ZipCode) || empty($DayTel) || empty($NightTel) || empty($Comments)) {
echo "<h2>Use Back - fill in all fields</h2>\n";
die ("Use back! ! ");
}

$todayis = date("l, F j, Y, g:i a");

//$attn = $attn;
$subject = "You have an email from your website";

$Comments = stripcslashes($Comments);

$message = " $todayis [EST] \n
Name: $FirstName $LastName \n
Email: $EmailFrom \n
Address 1: $Street1 \n
Address 2: $Street2 \n
City: $City \n
State: $State \n
Zip Code: $ZipCode \n
Daytime Telephone: $DayTel \n
Nighttime Telephone: $NightTel \n
Comments: $Comments \n
=========================
Additional Info: IP = $ip \n
Browser Info: $httpagent \n
Referral: $httpref \n
";

$from = "From: $EmailFrom\r\n";
$visitor = "$FirstName $LastName";

$emailProgress = mail("email@adress.com", $subject, $message, $from);
if ($emailProgress) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactok.html\">";
} else {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contacterror.html\">";
}

?>

<p align="center">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $EmailFrom ?> )
<br />
Address 1: <?php echo $Street1 ?>
<br />
Adress 2: <?php echo $Street2 ?>
<br />
City: <?php echo $City ?>
<br />
State: <?php echo $State ?>
<br />
Zip Code: <?php echo $ZipCode ?>
<br />
Daytime Telephone: <?php echo $DayTel ?>
<br />
Nighttime Telephone: <?php echo $NightTel ?>
<br />
Comments:<br />
<?php $notesout = str_replace("\r", "<br/>", $Comments);
echo $notesout; ?>
<br />
<?php echo $ip ?>

<br /><br />
<a href="index.html"> Go Home </a>
</p>

</body>
</html>



Thanks for helping me.
The Rock :D
Was This Post Helpful? 0
  • +
  • -

#8 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: Email Form Problems!

Posted 06 July 2009 - 01:06 PM

<?php if (isset($_POST['submit'])) { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>

<!-- Reminder: Add the link for the 'next page' (at the bottom) -->
<!-- Reminder: Change 'YourEmail' to Your real email -->

<?php

$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Street1 = $_POST['Street1'];
$Street2 = $_POST['Street2'];
$City = $_POST['City'];
$ZipCode = $_POST['ZipCode'];
$State = $_POST['State'];
$DayTel = $_POST['DayTel'];
$NightTel = $_POST['NightTel'];
$EmailFrom = $_POST['EmailFrom'];
$Comments = $_POST['Comments'];


if (eregi('http:', $Comments)) {
die ("Do NOT try that! ! ");
}
if(!$EmailFrom == "" && (!strstr($EmailFrom,"@") || !strstr($EmailFrom,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($FirstName) || empty($LastName) || empty($Street1) || empty($City) || empty($State) || empty($ZipCode) || empty($DayTel) || empty($NightTel) || empty($Comments)) {
echo "<h2>Use Back - fill in all fields</h2>\n";
die ("Use back! ! ");
}

$todayis = date("l, F j, Y, g:i a");

//$attn = $attn;
$subject = "You have an email from your website";

$Comments = stripcslashes($Comments);

$message = " $todayis [EST] \n
Name: $FirstName $LastName \n
Email: $EmailFrom \n
Address 1: $Street1 \n
Address 2: $Street2 \n
City: $City \n
State: $State \n
Zip Code: $ZipCode \n
Daytime Telephone: $DayTel \n
Nighttime Telephone: $NightTel \n
Comments: $Comments \n
=========================
Additional Info: IP = $ip \n
Browser Info: $httpagent \n
Referral: $httpref \n
";

$from = "From: $EmailFrom\r\n";
$visitor = "$FirstName $LastName";

$emailProgress = mail("email@email.com", $subject, $message, $from);

// i commented this out just so i would stay put after the email was sent and not redirected ...
if ($emailProgress) {
  //print "<meta http-equiv=\"refresh\" content=\"0;URL=contactok.html\">";
} else {
 //print "<meta http-equiv=\"refresh\" content=\"0;URL=contacterror.html\">";
}

?>

<p align="center">
Date: <?php echo $todayis ?>
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $EmailFrom ?> )
<br />
Address 1: <?php echo $Street1 ?>
<br />
Adress 2: <?php echo $Street2 ?>
<br />
City: <?php echo $City ?>
<br />
State: <?php echo $State ?>
<br />
Zip Code: <?php echo $ZipCode ?>
<br />
Daytime Telephone: <?php echo $DayTel ?>
<br />
Nighttime Telephone: <?php echo $NightTel ?>
<br />
Comments:<br />
<?php $notesout = str_replace("\r", "<br/>", $Comments);
echo $notesout; ?>
<br />
<?php echo $ip ?>

<br /><br />
<a href="index.html"> Go Home </a>
</p>

</body>
</html>
<?php die; }?>
<!-- DO NOT change ANY of the php sections -->
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />

<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <tr>
	<td>FirstName:*</td>
	<td><input type="text" name="FirstName"></td>
  </tr>
  <tr>
	<td>LastName:*</td>
	<td><input type="text" name="LastName"></td>
  </tr>
  <tr>
	<td>Address 1:*</td>
	<td><input type="text" name="Street1"></td>
  </tr>
  <tr>
	<td> Address 2:*</td>
	<td><input type="text" name="Street2"></td>
  </tr>
  <tr>
	<td>City:*</td>
	<td><input type="text" name="City"></td>
  </tr>
  <tr>
	<td>Zip Code:*</td>
	<td><input type="text" name="ZipCode"></td>
  </tr>
  <tr>
	<td>State:*</td>
	<td><input type="text" name="State"></td>
  </tr>
  <tr>
	<td>Day Telephone:*</td>
	<td><input type="text" name="DayTel"></td>
  </tr>
  <tr>
	<td>Night Telephone:*</td>
	<td><input type="text" name="NightTel"></td>
  </tr>
  <tr>
	<td>Email From:*</td>
	<td><input type="text" name="EmailFrom"></td>
  </tr>
  <tr>
	<td>Comments:*</td>
	<td><textarea name="Comments" cols="50"></textarea></td>
  </tr>
  <tr>
	<td><input type="submit" name="submit" value="Send Mail"></td>
  </tr>
  </form>




I was to lazy to create a second page so i made yours into one page and tested on my host with no issues ... sounds like you might have to verify if you can send emails using your host or not

This post has been edited by RPGonzo: 06 July 2009 - 01:08 PM

Was This Post Helpful? 0
  • +
  • -

#9 The Rock  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 24-September 07

Re: Email Form Problems!

Posted 06 July 2009 - 06:31 PM

RPGonzo,

You were correct. It was a server problems, but they couldn't open it up for me. But they gave me options to several scripts that they currently have as a default. So I redirected my contact form to that script and it worked magically. Thanks for your help!

The Rock :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1