SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 31 of 31
  1. #26
    SitePoint Zealot 810311's Avatar
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi Pullo,

    I just replaced the code in submit.php with the code you gave me and received message "something went wrong"...

  2. #27
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,045
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Aw! - that's weak!
    I'll get this set up on my server and see if I can do some troubleshooting.

  3. #28
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,045
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Ok, the only thing that I could find that was slightly wrong, was two variable names:

    Code:
    $mailcontent = "Name: ". $name. "\n".
                     "Subject: ". $subject. "\n".
                     "Email: ". $email. "\n\n".
                     $message;
    should have been:

    Code:
    $mailcontent = "Name: ". $fromname. "\n".
                   "Subject: ". $subject. "\n".
                   "Email: ". $emailfrom. "\n\n".
                   $message;
    but this makes your host's mail servers very fussy if they throw an error at that.

    Can you try something?

    Copy index.html and submit.php into a folder on your server.
    Access the form and try and use it to send a mail.
    This works for me.

    index.html

    Code:
    <!DOCTYPE HTML>
    <html>
      <head>
        <meta charset="utf-8">
        <title>Contact Us!</title>
        <style>
          * {
            margin: 0;
            padding: 0;
          }
    
          body {
            font-size: 62.5%;
            font-family: Helvetica, sans-serif;
          }
    
          p {
            font-size: 1.3em;
            margin-bottom: 15px;
          }
    
          #page-wrap {
            width: 660px;
            background: white;
            padding: 20px 50px 20px 50px;
            margin: 20px auto;
            height: auto !important;
          }
    
          #contact-area {
            width: 600px;
            margin-top: 25px;
          }
    
          #contact-area input, #contact-area textarea {
            padding: 5px;
            width: 471px;
            font-family: Helvetica, sans-serif;
            font-size: 1.4em;
            margin: 0px 0px 10px 0px;
            border: 2px solid #ccc;
          }
    
          #contact-area textarea {
            height: 90px;
          }
    
          #contact-area textarea:focus, #contact-area input:focus {
            border: 2px solid #900;
          }
    
          #contact-area input.submit-button {
            width: 100px;
            float: right;
          }
    
          label {
            float: left;
            text-align: right;
            margin-right: 15px;
            width: 100px;
            padding-top: 5px;
            font-size: 1.4em;
          }  
        </style>
      </head>
      <body>
    
        <div id="page-wrap">
          <h1>Contact form</h1>
    
          <div id="contact-area">
            <form method="post" action="submit.php">
    
              <label for="name">Name:</label>
              <input type="text" name="name" id="name" />
              
              <label for="subject">Subject:</label>
              <input type="text" name="subject" id="subject" />
        
              <label for="email">Email:</label>
              <input type="text" name="email" id="email" />
              
              <label for="message">Message:</label><br />
              <textarea name="message" rows="20" cols="20" id="message"></textarea>
    
              <input type="submit" name="submit" value="Submit" class="submit-button" />
            </form>
          </div>
        </div>
      </body>
    </html>
    submit.php

    Code:
    <?php
    $emailto = 'you@you.com';
    $toname = 'Your name';
    
    $fromname = filter_var($_POST['name'],FILTER_SANITIZE_STRING);
    $emailfrom = filter_var($_POST['email'],FILTER_SANITIZE_STRING, FILTER_VALIDATE_EMAIL);
    $subject = filter_var($_POST['subject'],FILTER_SANITIZE_STRING);
    
    $message = filter_var($_POST['message'],FILTER_SANITIZE_STRING);
    $error = "";
    
    $headers = 
      'Return-Path: ' . $emailfrom . "\r\n" . 
      'From: ' . $fromname . ' <' . $emailfrom . '>' . "\r\n" . 
      'X-Priority: 3' . "\r\n" . 
      'X-Mailer: PHP ' . phpversion() .  "\r\n" . 
      'Reply-To: ' . $fromname . ' <' . $emailfrom . '>' . "\r\n" .
      'MIME-Version: 1.0' . "\r\n" . 
      'Content-Transfer-Encoding: 8bit' . "\r\n" . 
      'Content-Type: text/plain; charset=UTF-8' . "\r\n";
    $params = '-f ' . $emailfrom;
    
    if (empty($fromname)){
      $error .= "You didn't enter a name <br />";
    }
    
    if (empty($subject)){
      $error .= "You didn't enter a subject <br />";
    }
    
    if (empty($emailfrom)){
      $error .= "You didn't enter an email address <br />";
    } elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})\.?$", $emailfrom)){
      $error .= "The email address appears to be invalid <br />";  
    }
    
    if (empty($message)){
      $error .= "You didn't enter a message <br />";
    }
    
    if (empty($error)) {
      $mailcontent = "Name: ". $fromname. "\n".
                     "Subject: ". $subject. "\n".
                     "Email: ". $emailfrom. "\n\n".
                     $message;
                     
      $success = mail($emailto, $subject, $mailcontent, $headers, $params);
    
      if ($success){
        echo "Mail sent successfully";
      }
      else{
        echo "Something went wrong";
      }
    } else {
      echo $error;
    }
    ?>
    Don't forget to change the variables $emailto and $toname accordingly.

  4. #29
    SitePoint Zealot 810311's Avatar
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I created a folder in www.domain/form and put 2 files there www.domain/form/index.html and submit.php....received message "something went wrong"..

  5. #30
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,045
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    That's a real shame.
    The code I posted works great for me, so there is something in there that your host's servers don't like.

    All you can do now is go through and start reverting back the values to hard-coded ones, e.g. change:

    Code:
    $fromname = filter_var($_POST['name'],FILTER_SANITIZE_STRING);
    to:

    Code:
    $fromname = 'FROM NAME';
    Then see if that makes a difference.
    If not, repeat with $emailfrom etc.

    Other suggestions would be to contact your host and see if they can spot anything that might cause an error, or ask over in the PHP forum.

    Sorry I can't help you more.

  6. #31
    SitePoint Zealot 810311's Avatar
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No worries. Thanks Pullo.


Bookmarks

Posting Permissions

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