I dont know whats wrong [SOLVED]

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
marcus_mercado
Forum Newbie
Posts: 2
Joined: Tue May 31, 2005 1:31 pm

I dont know whats wrong [SOLVED]

Post by marcus_mercado »

Hi I just started learning php and I am currently stuck on my first script. To be honest I dont really know what I have done wrong. I am trying to make a simple mailer containing two files the html where the form is and a php file which does the work

Here is the HTML file:

Code: Select all

<html>
<head>
  <meta
 content=&quote;text/html; charset=ISO-8859-1&quote;
 http-equiv=&quote;content-type&quote;>
  <title>mailer</title>
</head>
<body>
<form method=&quote;post&quote; action=&quote;send.php&quote;><span
 style=&quote;font-weight: bold;&quote;>Simple
HTML Mailer Example <br>
  <br>
  </span> <input
 name=&quote;group1&quote; value=&quote;html&quote; type=&quote;radio&quote;>
HTML <input name=&quote;group1&quote;
 value=&quote;text&quote; checked=&quote;checked&quote; type=&quote;radio&quote;>
Text<br>
  <table
 style=&quote;border-collapse: collapse; width: 588px; height: 194px;&quote;
 border=&quote;1&quote; bordercolor=&quote;#000000&quote;>
    <tbody>
      <tr>
        <td style=&quote;text-align: left;&quote;><span
 style=&quote;font-weight: bold;&quote;>To:</span></td>
        <td><input
 name=&quote;to&quote; size=&quote;45&quote;></td>
      </tr>
      <tr>
        <td height=&quote;4&quote; width=&quote;95&quote;>
        <b>From:</b>
        </td>
        <td height=&quote;4&quote; width=&quote;342&quote;>
        <input name=&quote;email&quote; size=&quote;45&quote;
 type=&quote;text&quote;></td>
      </tr>
      <tr>
        <td><span
 style=&quote;font-weight: bold;&quote;>Sender:</span></td>
        <td><input
 name=&quote;headers1&quote; size=&quote;45&quote;></td>
      </tr>
      <tr>
        <td><span
 style=&quote;font-weight: bold;&quote;>Reply To:</span></td>
        <td><input
 name=&quote;headers2&quote; size=&quote;45&quote;></td>
      </tr>
      <tr>
        <td><span
 style=&quote;font-weight: bold;&quote;>ReturnPath:</span></td>
        <td><input
 name=&quote;headers3&quote; size=&quote;45&quote;></td>
      </tr>
      <tr>
        <td height=&quote;27&quote; width=&quote;95&quote;>
        <b>Subject:</b></td>
        <td height=&quote;27&quote; width=&quote;342&quote;>
        <input name=&quote;subject&quote;
 size=&quote;45&quote; type=&quote;text&quote;></td>
      </tr>
      <tr>
        <td></td>
      </tr>
      <tr>
        <td height=&quote;20&quote; width=&quote;95&quote;><b>Message:</b></td>
        <td height=&quote;20&quote; width=&quote;342&quote;>
        <textarea name=&quote;message&quote;
 cols=&quote;60&quote; rows=&quote;15&quote;></textarea></td>
      </tr>
    </tbody>
  </table>
  <p style=&quote;text-align: center;&quote;>
  <input name=&quote;submit&quote; value=&quote;Submit&quote;
 type=&quote;submit&quote;><input
 name=&quote;reset&quote; value=&quote;Clear&quote; type=&quote;reset&quote;></p>
</form>
<br>
</body>
</html>
Here is the php "send.php"

Code: Select all

<?
if ($group1 == "text")
{
$headers4 = 'Content-Type: text/html; charset=ISO-8859-1\r\n'
else {$headers4 = 'X-Mailer: PHP3\r\n'}
$headers = "From: $headers1\r\n";
$headers .= "Reply-To: $headers2\r\n";
$headers .= "Return-Path: $headers3\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "$headers4"; 

mail($to,$subject,$message,$headers)
echo "An e-mail was sent to $to";
header("location: mailer.html"); 
} else {
echo "Check the Fields dude";
}
?>
Can anyone fix the code please.
Last edited by marcus_mercado on Tue May 31, 2005 2:06 pm, edited 1 time in total.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

you have one if and two elses. Indent your code to make it readable. Easier to find mistakes that way.

Code: Select all

<?php
if ($group1 == "text") {
  $headers4 = 'Content-Type: text/html; charset=ISO-8859-1\r\n' # << no semicolon
  else {$headers4 = 'X-Mailer: PHP3\r\n'} # << where's this else come from? (plus, no semicolon again)
  $headers = "From: $headers1\r\n";
  $headers .= "Reply-To: $headers2\r\n";
  $headers .= "Return-Path: $headers3\r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "$headers4"; 
 
  mail($to,$subject,$message,$headers) # << no semicolon
  echo "An e-mail was sent to $to"; # << if you echo this here...
  header("location: mailer.html"); # and change the location here, then the echo is never seen.
} else {
  echo "Check the Fields dude";
}
?>
marcus_mercado
Forum Newbie
Posts: 2
Joined: Tue May 31, 2005 1:31 pm

Post by marcus_mercado »

thanks dude I got everything to work

Code: Select all

<?
if ($group1 == "text")
{
$headers4 = 'X-Mailer: PHP3\r\n';
} else {$headers4 = 'Content-Type: text/html; charset=ISO-8859-1\r\n';
}
$headers = "From: $headers1\r\n";
$headers .= "Reply-To: $headers2\r\n";
$headers .= "Return-Path: $headers3\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "$headers4"; 
mail($to,$subject,$message,$headers);
header("location: mailer.html"); 
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

your script requires register global to be ON, which is OFF by default. And if it is on, I would suggest turning it off immediatly. Why? :arrow: http://www.php.net/register_globals.
To append your post variables switch your variables

from $message to $_POST['message'] since it is coming through a form. If your method is send through 'get' then the variables will be passed through the URL.. which they will then require the use of $_GET['message'].

:arrow: http://www.php.net/variables.predefined
Post Reply