We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
PHP Mail Form troubles
Topic Started: Feb 5 2007, 04:53 PM (436 Views)
Jpec07
Member Avatar
Member
[ *  * ]
Solved!

Hey again, all, I'm having some difficulty again, only this time it's with a mailing script I've been working on. Basically, when someone fills out a form, I want it to email me the information they filled out - it's not doing this, and I have no clue why not (there's no error message). Perhaps you could help me out?

Here's the code:
Code:
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Bonhoeffer Ticketing</title>
</head>
<body>
<center><form action="tickets.php" method="post">
<table border="0" width="500" cellpadding="0" cellspacing="3">
<tr>
<td valign="top" align="right">Name:<br></td>
<td valign="top"><input type="text" name="name" /><br></td>
</tr>

<tr>
<td valign="top" align="right">Phone Number:<br></td>
<td valign="top"><input type="text" name="phone" /><br></td>
</tr>

<tr>
<td valign="top" align="right">Email Address:<br></td>
<td valign="top"><input type="text" name="email" /><br></td>
</tr>

<tr>
<td valign="top" align="right">Number of Attendees:<br></td>
<td valign="top"><input type="text" name="attend" /><br></td>
</tr>

<tr>
<td valign="top" align="right">Date Attending:<br></td>
<td valign="top"><select name="date">
<option>Choose One</option>
<option value="Friday, 2/23/07">Friday, 2/23/07</option>
<option value="Saturday, 2/24/07">Saturday, 2/24/07</option>
</select><br></td>
</tr>

</table>
<input type="submit" name="submit" value="Submit" /></form></center>

</body>
</html>


And here's the actual mailing script itself (tickets.php):

Code:
 
<?php
if ($submit) {
$name = $_POST["name"];
$phone = $_POST["phone"];
$email = $_POST["email"];
$attend = $_POST["attend"];
$date = $_POST["date"];
$submit = $_POST["submit"];
//mail application to site admin
 // recipients
 $to  = "jpec07@charter.net" . ", "; // note the comma
 $to .= "jpec07@gmail.com";

// subject
$subject = "Bonhoeffer";

// message
$message = "
<html>
<head>
 <title>Bonhoeffer Ticket Reservation Information</title>
</head>
<body>
<table>
 <tr>
  <td>Name:</td>
 <td>$name</td>
 </tr>
   <tr>
  <td>Phone Number:</td>
 <td>$phone</td>
 </tr>
 <tr>
  <td>Email:</td>
 <td>$email</td>
 </tr>
 <tr>
  <td>Number of Attendees Reserved:</td>
 <td>$attend</td>
 </tr>
 <tr>
  <td>Date of Attendance:</td>
 <td>$date</td>
 </tr>
</table>
</body>
</html>
";

// To send HTML mail, you can set the Content-type header.
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

// additional headers
$headers .= "To: Jpec07@charter.net, Jpec07@gmail.com\r\n";

// and now mail it
mail($to, $subject, $message, $headers);
//end the mail function

 // process form
 echo "Thank you. Your request has been processed. You will receive an email shortly with your ticket. <b>Please print this and bring it with you.</b> <a href=\"content.html\">Back.</a>";

}
?>


Any help you can offer would be most appreciated. ^_^
Offline Profile Quote Post Goto Top
 
Sani
Member Avatar
Member
[ *  *  *  *  * ]
Try changing $submit to $_POST['submit']..
Offline Profile Quote Post Goto Top
 
Garath531
Member Avatar
Look, up in the sky! It's a bird! It's a plane! It's Superman!
[ *  *  *  * ]
My advice would be to use
Quote:
 

<form action="mailto:email address goes here." action-"post">

Rather than fooling with PhP
Offline Profile Quote Post Goto Top
 
Ben
Member Avatar
Quantum-locked when observed.

Garath
February 5, 2007 10:38 PM
My advice would be to use
Quote:
 

<form action="mailto:email address goes here." action-"post">

Rather than fooling with PhP

The "mailto:" method will not mail the information in the form. Rather, it opens up one's email program and puts that information in the email (if you're lucky). If you want to send the email from your server, you need to use a server-side scripting language.

Sani's advice is correct. In your if($submit) condition to check if the form has been submitted, you should use $_POST['submit'] instead, because register_globals is probably on.
Offline Profile Quote Post Goto Top
 
Jpec07
Member Avatar
Member
[ *  * ]
I actually tried it, $submit = $_POST['submit']; before if($submit). The problem is that I can't be sure if that was the problem or not. It turns out the SMTP server my host was using wasn't enabled for my hosting plan, so I made a switch to one that was and now all is good.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply