Results 1 to 5 of 5

Thread: php email form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    366

    php email form

    Hi here is an php email form, and remember very new to php, it doesnt seem to work, i cant get it to email me at the given address although the sent page comes up when i use it? Anyone got any ideas?
    Code:
    <html>
    <body>
    <?php
    if (isset($_REQUEST['email']))
    //if "email" is filled out, send email
      {
      //send email
      $email = $_REQUEST['email'] ; 
      $subject = $_REQUEST['subject'] ;
      $message = $_REQUEST['message'] ;
      mail( "[email protected]", "Subject: $subject",
      $message, "From: $email" );
      echo "Sent";
      }
    else
    //if "email" is not filled out, display the form
      {
      echo "<form method='post' action='mailform.php'>
      Email: <input name='email' type='text' /><br />
      Subject: <input name='subject' type='text' /><br />
      Message:<br />
      <textarea name='message' rows='15' cols='40'>
      </textarea><br />
      <input type='submit' />
      </form>";
      }
    ?>>
    
    
    </body>
    </html>
    Thanks
    Alex

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: php email form

    read up on mail with php here.

    then, read up on the mail() function in php here.

    to see if mail() is having a trouble when being called, add an "or die()" statement to your mail() call. for example:
    PHP Code:
    mail(blahblahblahblah) or die("there was an error sending the message"); 
    of course, I hope you realize you need to fill in the parameters with something other than "blah."

    next, if it does give you the error message and it doesn't say anything, you have error reporting suppressed. you need to look at your webserver's error log (which should contain these errors), or you can manually re-set the exceptions for your script using the error_reporting() function. you will want to use E_ALL to find all errors happening.

    this should help you find out if the problem is your headers or a bad connection to your smtp server -- or something else.

    edit: by the way, adding "subject: [subject]" is a bad idea, simply because when you get your emails, the subject will literally be "subject: [subject]." you should just make your subject "[subject]" instead.
    Last edited by kows; Mar 4th, 2007 at 02:41 AM.

  3. #3
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: php email form

    Are you using your ISPs smtp? With my hosting one of the SMTP usage rules were that the outgoing address was [email protected].

    ILMV

  4. #4
    Addicted Member
    Join Date
    Jan 2006
    Posts
    247

    Re: php email form

    Code:
    ?>>
    That is a little strange....



  5. #5
    Lively Member rasana's Avatar
    Join Date
    Jan 2007
    Location
    Mumbai, (India)
    Posts
    94

    Re: php email form

    Quote Originally Posted by youngnoviceinneedofh
    Hi here is an php email form, and remember very new to php, it doesnt seem to work, i cant get it to email me at the given address although the sent page comes up when i use it? Anyone got any ideas?
    Code:
    <html>
    <body>
    <?php
    if (isset($_REQUEST['email']))
    //if "email" is filled out, send email
      {
      //send email
      $email = $_REQUEST['email'] ; 
      $subject = $_REQUEST['subject'] ;
      $message = $_REQUEST['message'] ;
      mail( "[email protected]", "Subject: $subject",
      $message, "From: $email" );
      echo "Sent";
      }
    else
    //if "email" is not filled out, display the form
      {
      echo "<form method='post' action='mailform.php'>
      Email: <input name='email' type='text' /><br />
      Subject: <input name='subject' type='text' /><br />
      Message:<br />
      <textarea name='message' rows='15' cols='40'>
      </textarea><br />
      <input type='submit' />
      </form>";
      }
    ?>>
    
    
    </body>
    </html>
    Thanks
    Alex
    modify your mail() as

    PHP Code:
    $sendto="[email protected]";

    $headers "From: $email\r\nCC:$ccto\r\nContent-type: text/html;charset=us-ascii";

    mail($sendto$subject$message$headers); 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width