?
Solved

What am I doing wrong

Posted on 2005-04-01
10
Medium Priority
?
247 Views
Last Modified: 2008-03-06
I am trying to make this form an e-mail to me

what am I doing wrong

here is the code




<?

$fname = "FromMe";           // Name to be shown in from details.
$femail = "asim@alpha-t.org";  // E-mail address to be shown in  from details.


//-------------------------------------------------------------------------------------------

if(!isset($action)){

?>


<form name="form1" method="post" action="mailform.php">
<input name="action" type="hidden" value="send">
<table width="370" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td width="120" >to e-mail:</td>
    <td width="250" ><input name="toemail" type="text" size="30"></td>
  </tr>

  <tr>
    <td>subject:</td>
    <td><input name="subject" type="text" size="30" value=""></td>
  </tr>
  <tr>
    <td  valign="top">message:</td>
    <td>
       <textarea name="message" rows="5" cols="35">

       </textarea>
      </td>
  </tr>
  <tr>
    <td>type:</td>
    <td>
        text&nbsp;<input name="rdType" type="radio" value="0" checked>
        &nbsp;&nbsp;
        html&nbsp;<input name="rdType" type="radio" value="1">
      </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
       <input name="cmdSend" type="submit" value="send">&nbsp;
       <input name="cmdReset" type="reset" value="reset">
      </td>
  </tr>
</table>
</form>


<?
}else{

 $from = $fname . "<$femail>";
 $headers = "From: $from \r\n";
 if($rdType == 1){
   $headers .= "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1";
   $message = stripslashes($message);
 }else{
   $headers .= "MIME-Version: 1.0\n" . "Content-type: text/plain; charset=iso-8859-1";
 }
 $ok = @mail($toemail, $subject, $message, $headers);
  if ($ok) {
   echo "<center><font class='general'>Mail sent successfully. Thank you.</font></center>";
  } else {
   echo "<center><font class='general'>Mail could not be sent.</font></center>";
  }
 }

?>
Thanks
0
Comment
Question by:syedasimmeesaq
  • 5
  • 3
  • 2
10 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 1000 total points
ID: 13684873
If you have a newer PHP version, you have to refer to the form variables as $_POST['fieldName'] instead of $fieldName

example:

$_POST['action'] instead of $action.

Try this code:


<?

$fname = "FromMe";           // Name to be shown in from details.
$femail = "asim@alpha-t.org";  // E-mail address to be shown in  from details.


//-------------------------------------------------------------------------------------------

if(!isset($POST['action'])){

?>


<form name="form1" method="post" action="mailform.php">
<input name="action" type="hidden" value="send">
<table width="370" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td width="120" >to e-mail:</td>
    <td width="250" ><input name="toemail" type="text" size="30"></td>
  </tr>

  <tr>
    <td>subject:</td>
    <td><input name="subject" type="text" size="30" value=""></td>
  </tr>
  <tr>
    <td  valign="top">message:</td>
    <td>
      <textarea name="message" rows="5" cols="35">

      </textarea>
     </td>
  </tr>
  <tr>
    <td>type:</td>
    <td>
       text&nbsp;<input name="rdType" type="radio" value="0" checked>
       &nbsp;&nbsp;
       html&nbsp;<input name="rdType" type="radio" value="1">
     </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
      <input name="cmdSend" type="submit" value="send">&nbsp;
      <input name="cmdReset" type="reset" value="reset">
     </td>
  </tr>
</table>
</form>


<?
}else{
 $message = $_POST['message'];
 $subject = $_POST['subject'];
 $toemail = $_POST['toemail'];
 
 $from = $fname . "<$femail>";
 $headers = "From: $from \r\n";
 if($rdType == 1){
   $headers .= "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1";
   $message = stripslashes($message);
 }else{
   $headers .= "MIME-Version: 1.0\n" . "Content-type: text/plain; charset=iso-8859-1";
 }
 $ok = @mail($toemail, $subject, $message, $headers);
  if ($ok) {
   echo "<center><font class='general'>Mail sent successfully. Thank you.</font></center>";
  } else {
   echo "<center><font class='general'>Mail could not be sent.</font></center>";
  }
 }

?>
0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 13684929
Thanks for your reply
Nope it didn't work
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13684947
Sorry

$POST['action'] should be $_POST['action']

Try this one:

<?

$fname = "FromMe";           // Name to be shown in from details.
$femail = "asim@alpha-t.org";  // E-mail address to be shown in  from details.


//-------------------------------------------------------------------------------------------

if(!isset($_POST['myAction'])){

?>


<form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
<input name="myAction" type="hidden" value="send">
<table width="370" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td width="120" >to e-mail:</td>
    <td width="250" ><input name="toemail" type="text" size="30"></td>
  </tr>

  <tr>
    <td>subject:</td>
    <td><input name="subject" type="text" size="30" value=""></td>
  </tr>
  <tr>
    <td  valign="top">message:</td>
    <td>
      <textarea name="message" rows="5" cols="35">

      </textarea>
     </td>
  </tr>
  <tr>
    <td>type:</td>
    <td>
       text&nbsp;<input name="rdType" type="radio" value="0" checked>
       &nbsp;&nbsp;
       html&nbsp;<input name="rdType" type="radio" value="1">
     </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
      <input name="cmdSend" type="submit" value="send">&nbsp;
      <input name="cmdReset" type="reset" value="reset">
     </td>
  </tr>
</table>
</form>


<?
}else{
 $message = $_POST['message'];
 $subject = $_POST['subject'];
 $toemail = $_POST['toemail'];
 
 $from = $fname . "<$femail>";
 $headers = "From: $from \r\n";
 if($rdType == 1){
   $headers .= "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1";
   $message = stripslashes($message);
 }else{
   $headers .= "MIME-Version: 1.0\n" . "Content-type: text/plain; charset=iso-8859-1";
 }
 $ok = @mail($toemail, $subject, $message, $headers);
  if ($ok) {
   echo "<center><font class='general'>Mail sent successfully. Thank you.</font></center>";
  } else {
   echo "<center><font class='general'>Mail could not be sent.</font></center>";
  }
 }

?>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 13684965
Nope. Still not working... Doesn't send an e-mail to asimmeesaq@hotmail.com, which I put in the e-mail to section of the form [toemail].
Thanks
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13684977
Do you get this error message:

Mail could not be sent

?

Have you a connection to a mail server?
0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 13685004
I get the Mail sent message.

I aqm sending it using my website server.
Thanks
0
 
LVL 1

Expert Comment

by:teleute
ID: 13690526
Do you have another address you could test sending it to?  I've had hotmail block web form-type email as spam on more than a few occasions...
0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 13693032
I tried other e-mail addresses ..Its still not working. I think I need to post this question in web development . You think?
0
 
LVL 1

Expert Comment

by:teleute
ID: 13693343
Your web server - is it Windows or *nix?  Here's an excerpt from php.net:

" Note:  The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

    Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP.

    As such, the to parameter should not be an address in the form of "Something <someone@example.com>". The mail command may not parse this properly while talking with the MTA. "

So if it's Windows, the form of the "to:" address may be the issue.
0
 
LVL 9

Author Comment

by:syedasimmeesaq
ID: 13702033
Thank you for trying to help me. I have solved the problem. the code below works. Since you were the only person who tried to help me, I will give you the points. But for the future refrences, I am copying and pasting the code. In case some one requires a simple form.
Thank You
Asim

<?

// $mailto - set to the email address you want the form
// sent to, eg
//$mailto            = "youremailaddress@example.com" ;

$mailto = 'your@example.com';

// $subject - set to the Subject line of the email, eg
//$subject      = "Feedback Form" ;

$subject = "Question Form" ;

// the pages to be displayed, eg
$formurl            = "http://www.example.com/feedback.html" ;
$errorurl            = "http://www.example.com/error.html" ;
$thankyouurl      = "http://www.example.com/thankyou.html" ;


// -------------------- END OF CONFIGURABLE SECTION ---------------

$name = $_POST['name'] ;
$Phone = $_POST['Phone'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
      header( "Location: $formurl" );
      exit ;
}
if (empty($name) || empty($email) || empty($Phone) || empty($comments)) {
   header( "Location: $errorurl" );
   exit ;
}
if (get_magic_quotes_gpc()) {
      $comments = stripslashes( $comments );
}

$messageproper =

      "This message was sent from:\n" .
      "$http_referrer\n" .
      "------------------------- COMMENTS -------------------------\n\n" .
      $comments .
      "\n" .
      "Phone Number of the Prospect is:" .
      $Phone .
      "\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>\nReply-To: \"$name\" <$email>\nX-Mailer: chfeedback.php 2.03" );
header( "Location: $thankyouurl" );
exit ;

?>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question