?
Solved

What am I doing wrong

Posted on 2005-04-01
10
Medium Priority
?
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

765 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