Simple Email Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Simple Email Form

Post by nickman013 »

Hello,

I cant seem to spot the error of this. I have a form in a iFrame, and it proccesses the form in the iFrame on another page.

The form code is,

Code: Select all

<center>
	<font size=3 color=blue>If you have a muot that you want us to research on, enter its name here.</font><br>
	<form action=/quicklist/process.php method=post>
		<input type=text maxlenth=40 name=name>
		<input type="button" Value="Submit!" onclick="check(form,form.elements.length)">
		<input type="hidden" name="r_name" value="You did not enter the muots name.">
	</form>
</center>
The reason the submit button is a button, is because I have a code that checks and makes sure everything is entered in the form.

The process.php is this

Code: Select all

<?php
mail("nickman013@mac.com","MUOT QUICKLIST",$name);
?>
<font color=white><center><font size=5><b>
Thank You</b></font></center>
I dont get a syntax error. It says Thank You. I get a email, but it doesnt have the $name value.

Any help would be great, thanks!
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Try this..

It is not secure by the way..

Code: Select all

mail("nickman013@mac.com","MUOT QUICKLIST",$_POST['name']);
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Thank You.

Register Globals is on. But thanks alot!
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Now I am trying to do this.

Code: Select all

<?
$_POST['name'] == $name;
function generateEmail($name)
{
return "
Someone wants us to hunt down and write a report on a muot that goes by the name <font size=3 color=red><b> $name </b></font>
";
}
mail("nickman013@mac.com","MUOT SUBMITION",generateEmail($name), "Content-type: text/html\r\n");
?>
<font color=white><center><font size=5><b>
Thank You</b></font></center>
But it doesnt work. Thanks for all of your help.

PS. Sorry for double posting.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

nickman013 wrote:Now I am trying to do this.

Code: Select all

<?
$_POST['name'] == $name;
I wouldn't use short tags. And I'm not sure why you have that line above as it's not doing anything for you. == is a comparison operator, not an assignment operator.

I know this function works..

Code: Select all

function send_mail($from, $to, $subject, $body) {
  $header = "From: " . $from . "\n";
  mail($to, $subject, $body, $header);
}
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Ok this is my process script, I dont even get an email.

Code: Select all

<?
$from = "MUOT.NET";
$to = "nickman013@mac.com";
$subject = "MUOT QUICKLIST";
$body = "Someone wants us to hunt down and write a report on a muot that goes by the name <font size=3 color=red><b> $name </b></font>";
function send_mail($from, $to, $subject, $body) { 
$header = "From: " . $from . "\n"; 
mail($to, $subject, $body, $header); 
}
?>
<font color=white>
	<center><font size=5><b>
				Thank You
			</b>
		</font>
	</center>
I dont get a parse error either.

Any help would be great !
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

The function is not being called...

Code: Select all

<?php
$from = "MUOT.NET";
$to = "nickman013@mac.com";
$subject = "MUOT QUICKLIST";
$body = "Someone wants us to hunt down and write a report on a muot that goes by the name <font size=3 color=red><b> $name  </b></font>";
function send_mail($from, $to, $subject, $body) {
$header = "From: " . $from . "\n";
mail($to, $subject, $body, $header);
}

if ((isset($_POST['name'])) && ($_POST['name'] != '')) {
    send_mail($from, $to, $subject, $body);
}


?>
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

My code now,

Code: Select all

<?php
$from = "MUOT.NET"; 
$to = "nickman013@mac.com"; 
$subject = "MUOT QUICKLIST"; 
$body = "Someone wants us to hunt down and write a report on a muot that goes by the name <font size=3 color=red><b> $name  </b></font>"; 
function send_mail($from, $to, $subject, $body) { 
$header = "From: " . $from . "\n"; 
mail($to, $subject, $body, $header); 
} 
if ((isset($_POST['name'])) && ($_POST['name'] != '')) { 
    send_mail($from, $to, $subject, $body); 
} 
?>
<font color=white>
	<center><font size=5><b>
				Thank You
			</b>
		</font>
	</center>
The email I receive
Someone wants us to hunt down and write a report on a muot that goes by the name <font size=3 color=red><b> </b></font>
I made sure that the form input name was correct, and it was.

I appreciate all your help!
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

You should be using quotes around the attributes, maybe that is causing the problem...

Code: Select all

<center>
   <font size=3 color=blue>If you have a muot that you want us to research on, enter its name here.</font><br>
   <form action="/quicklist/process.php" method="post">
      <input type="text" maxlenth="40" name="name">
      <input type="button" Value="Submit!" onclick="check(form,form.elements.length)">
      <input type="hidden" name="r_name" value="You did not enter the muots name.">
   </form>
</center> 
If that doesn't fix it, on the page with the mail function, paste the results of this..

Code: Select all

echo '<pre>';
print_r($_POST);
echo '</pre>';
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

The fixed the attributes, and it didnt work.

The results were
Array
(
[name] => ok
[r_name] => You did not enter the muots name.
)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Well that doesn't make any sense then. If this doesn't fix it I'm not sure I can help you. I'm not sure your statement about Globals being turned on is correct.

Code: Select all

$body = "Someone wants us to hunt down and write a report on a muot that goes by the name <font size=3 color=red><b> " . $_POST['name'] . " </b></font>";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

astions wrote:I'm not sure your statement about Globals being turned on is correct.
Let's find out!

nickman013,
Run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array(0, false, '', null, 'off');
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
$rg = (in_array(strtolower(ini_get('register_globals')), $neg) ? 'Off' : 'On');
$de = (in_array(strtolower(ini_get('display_errors')), $neg) ? 'Off' : 'On');
$so = (in_array(strtolower(ini_get('short_open_tag')), $neg) ? 'Off' : 'On');
$le = '';
$cli = (php_sapi_name() == 'cli');
$eol = ($cli ? "\n" : "<br />\n");

$gle = get_loaded_extensions();
$rows = array();
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
    $le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . "\n";
}
if ($cli)
{
     $le = $eol . $le;
}
else
{
 $le = '<pre>' . $le . '</pre>';
}

$ec = array(
   'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
   'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
   'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
   'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
   if (($t & $v) == $v)
   {
      $e[] = $n;
      $t ^= $v;
   }
}
$er = $er . ' (' . implode(' | ', $e) . ')';

if (!$cli)
{
  echo '<html><head><title>quick info</title></head><body>' . "\n";
}

echo 'PHP Version: ' . $ve . $eol;
echo 'PHP OS: ' . $os . $eol;
echo 'Error Reporting: ' . $er . $eol;
echo 'Register Globals: ' . $rg . $eol;
echo 'Short Tags: ' . $so . $eol;
echo 'Display Errors: ' . $de . $eol;
echo 'Loaded Extensions:' . $le . $eol;

if (!$cli)
{
  echo '</body></html>' . "\n";
}

?>
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

It was my mistake. Register globals was not turned on in the folder that the process.php was in.

Thank you. I have one for question, how can I get the email to accept HTML.

THANKS SO MUCH! :D
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I believe the easiest way to send HTML emails would be to use d11wtq's swiftmailer..

viewtopic.php?t=48055
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Thank you.
Post Reply