Help! Problems with a form mail script in html and php....

  • mlisubaru
  • Newbie
  • Newbie
  • mlisubaru
  • Posts: 5

Post 3+ Months Ago

I'm trying to make a simple email form, but I'm having a really hard time with it. Would anyone mind looking over the script? I have it in two parts: an html file and a php file.

html:

Code: [ Select ]
<form method="post" action="email.php" name="billform">
<input type="hidden" name="to" value="mchild2@osa.org">
<input type="hidden" name="subject" value="High-speed Internet Access Billing">
First Name:
<input name="firstname" type="text" size="30">
<br>
Last Name:
<input name="lastname" type="text" size="30">
<br>
Room #:
<input name="roomno" type="text" size="5">
<br>
I wish to purchase
<input name="days" type="text" size="5">
days of internet access.<br>
<input type="submit" name="Submit" value="I Authorize Billing">
&
<input type="reset" name="Clear" value="Clear">
</font></p>
</form>
  1. <form method="post" action="email.php" name="billform">
  2. <input type="hidden" name="to" value="mchild2@osa.org">
  3. <input type="hidden" name="subject" value="High-speed Internet Access Billing">
  4. First Name:
  5. <input name="firstname" type="text" size="30">
  6. <br>
  7. Last Name:
  8. <input name="lastname" type="text" size="30">
  9. <br>
  10. Room #:
  11. <input name="roomno" type="text" size="5">
  12. <br>
  13. I wish to purchase
  14. <input name="days" type="text" size="5">
  15. days of internet access.<br>
  16. <input type="submit" name="Submit" value="I Authorize Billing">
  17. &
  18. <input type="reset" name="Clear" value="Clear">
  19. </font></p>
  20. </form>



The PHP doc (in its entirety):

Code: [ Select ]
<?php

$msg = array($firstname, $lastname, $roomno, $days);
$firstname = 'firstname';
$lastname = 'lastname';
$roomno = 'roomno';
$days = 'days';

$mailheaders = "$REMOTE_ADDR\n";

mail($name, $email, join("\n", $msg), $mailheaders);

?>
<html>
<head>
<title> Thank you </title>
<style type="text/css">
#main
{position: absolute;
top: 200px;
left: 325px;
width:450 px;
}
</style>
<script language="JavaScript"><!--
setTimeout("top.location.href = 'http://www.yahoo.com'",0);
//--></script>
</head>
<body>
<div id="main">
Thank you for your submission. If you are not redirected, please <a href=http://www.yahoo.com">click here</a>.
</div>
</body>
  1. <?php
  2. $msg = array($firstname, $lastname, $roomno, $days);
  3. $firstname = 'firstname';
  4. $lastname = 'lastname';
  5. $roomno = 'roomno';
  6. $days = 'days';
  7. $mailheaders = "$REMOTE_ADDR\n";
  8. mail($name, $email, join("\n", $msg), $mailheaders);
  9. ?>
  10. <html>
  11. <head>
  12. <title> Thank you </title>
  13. <style type="text/css">
  14. #main
  15. {position: absolute;
  16. top: 200px;
  17. left: 325px;
  18. width:450 px;
  19. }
  20. </style>
  21. <script language="JavaScript"><!--
  22. setTimeout("top.location.href = 'http://www.yahoo.com'",0);
  23. //--></script>
  24. </head>
  25. <body>
  26. <div id="main">
  27. Thank you for your submission. If you are not redirected, please <a href=http://www.yahoo.com">click here</a>.
  28. </div>
  29. </body>


When I fill out the form and click send, it sends me to the "thank you" page which redirects me, but I never receive an email. Can anyone help me?
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

I've never seen the recipient listed as "to" in any other language.

Example from your script:
Code: [ Select ]
<input type="hidden" name="to" value="mchild2@osa.org">

Try changing it to:
Code: [ Select ]
<input type="hidden" name="recipient" value="mchild2@osa.org">

and see if that works.
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

"to" is just the variable used to call the recipient later...

Code: [ Select ]
mail($name, $email, join("\n", $msg), $mailheaders);


You seem to have the variables rather mixed up, plus I don't see where $name is defined, it should probably be $to. This works:
Code: [ Select ]
mail (
"$to",
"$subject",
"Name: $firstname" . " $lastname," . "Room #: $roomno" . "Days Ordered: $days",
"From: $email"
);

//I am unsure what any of this is:

$firstname = 'firstname';
$lastname = 'lastname';
$roomno = 'roomno';
$days = 'days';

//because I don't see it called anywhere in the script.
  1. mail (
  2. "$to",
  3. "$subject",
  4. "Name: $firstname" . " $lastname," . "Room #: $roomno" . "Days Ordered: $days",
  5. "From: $email"
  6. );
  7. //I am unsure what any of this is:
  8. $firstname = 'firstname';
  9. $lastname = 'lastname';
  10. $roomno = 'roomno';
  11. $days = 'days';
  12. //because I don't see it called anywhere in the script.


I included a From: $email, which isn't necissary.

This is from the PHP Manual page of mail();
Quote:
bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]])


Maybe that would help. And the actualy page:
http://www.php.net/manual/en/function.mail.php
  • mlisubaru
  • Newbie
  • Newbie
  • mlisubaru
  • Posts: 5

Post 3+ Months Ago

That seems to work, except the email doesn't give me the data, just

"Name: firstname lastname,Room #: roomnoDays Ordered: days"

html:
Code: [ Select ]
<form method="post" action="email.php" name="billform">
<input type="hidden" name="to" value="mchild2@osa.org">
<input type="hidden" name="subject" value="High-speed Internet Access Billing">
    First Name: 
     <input name="firstname" type="text" size="30">
     <br>
    Last Name:
    <input name="lastname" type="text" size="30">
     <br>
    Room #:
    <input name="roomno" type="text" size="5">
     <br>
    I wish to purchase
    <input name="days" type="text" size="5">
days of internet access.
<br>
    <input type="submit" name="Submit" value="I Authorize Billing"> 
    &
    <input type="reset" name="Clear" value="Clear">
</font></p>
   </form>
  1. <form method="post" action="email.php" name="billform">
  2. <input type="hidden" name="to" value="mchild2@osa.org">
  3. <input type="hidden" name="subject" value="High-speed Internet Access Billing">
  4.     First Name: 
  5.      <input name="firstname" type="text" size="30">
  6.      <br>
  7.     Last Name:
  8.     <input name="lastname" type="text" size="30">
  9.      <br>
  10.     Room #:
  11.     <input name="roomno" type="text" size="5">
  12.      <br>
  13.     I wish to purchase
  14.     <input name="days" type="text" size="5">
  15. days of internet access.
  16. <br>
  17.     <input type="submit" name="Submit" value="I Authorize Billing"> 
  18.     &
  19.     <input type="reset" name="Clear" value="Clear">
  20. </font></p>
  21.    </form>


php:
Code: [ Select ]
<?php

$msg = array($firstname, $lastname, $roomno, $days);
$firstname = 'firstname';
$lastname = 'lastname';
$roomno = 'roomno';
$days = 'days';

$mailheaders = "$REMOTE_ADDR\n";

mail (
"$to",
"$subject",
"Name: $firstname" . " $lastname," . "Room #: $roomno" . "Days Ordered: $days"
); 

?>
  1. <?php
  2. $msg = array($firstname, $lastname, $roomno, $days);
  3. $firstname = 'firstname';
  4. $lastname = 'lastname';
  5. $roomno = 'roomno';
  6. $days = 'days';
  7. $mailheaders = "$REMOTE_ADDR\n";
  8. mail (
  9. "$to",
  10. "$subject",
  11. "Name: $firstname" . " $lastname," . "Room #: $roomno" . "Days Ordered: $days"
  12. ); 
  13. ?>


Any ideas? Thank you -so- much for your help!!![/code]
  • mlisubaru
  • Newbie
  • Newbie
  • mlisubaru
  • Posts: 5

Post 3+ Months Ago

LoL Nevermind! I figured it out! It works perfectly. Thank you so much!!!!
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

Yep like I said, I don't know why you were defining those variables....
  • mlisubaru
  • Newbie
  • Newbie
  • mlisubaru
  • Posts: 5

Post 3+ Months Ago

Gah. I thought it was all smoothed out. I'm having one more prob. with this... For whatever reason the data will send to some email accounts but not others. I've tried sending it to 4, and out of those 4, 2 worked perfectly and the other 2 not at all. Anyone ever experience this before? What should I do?
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9092
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Are you receiving any errors? For the 2 that did not work are you able to send a regular e-mail to those? Is there any difference between the email accounts that work versus the email accounts that did not work?
  • mlisubaru
  • Newbie
  • Newbie
  • mlisubaru
  • Posts: 5

Post 3+ Months Ago

I'm not receiving any errors.... It still goes to the "thank you" page and forwards to the main page, but the email never goes through (for the 2 disfunctional ones). All the emails were on different domains (which were official--company emails). I just tried it on yahoo, and it does work there, so I'm really perplexed about what's happening. This is really bizarre! Oh, and thank you so much for helping me!
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9092
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

To me it sounds like your script is working fine, and it might be an email issue on your other servers? Try sending a regular email (not using your form that is) to the 2 emails that do not work and see if they receive that.

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 128 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.