SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    email is not sent

    Hi.
    Iam trying to sent this form values to my email
    Its not working
    Can anyone help to solve this..

    This is my form

    PHP Code:
    <form method="POST" action="sendemail.php">
    <
    table width="450px">
    <
    tr>
     <
    td valign="top">
      <
    label for="name">Name </label>
     </
    td>
     <
    td valign="top">
      <
    input  type="text" name="name" maxlength="50" size="30">
     </
    td>
    </
    tr>
    <
    tr>
     <
    td valign="top">
      <
    label for="organisation">Organisation </label>
     </
    td>
     <
    td valign="top">
      <
    input  type="text" name="organisation" maxlength="50" size="30">
     </
    td>
    </
    tr>
    <
    tr>
     <
    td valign="top">
      <
    label for="contact">Contact no </label>
     </
    td>
     <
    td valign="top">
      <
    input  type="text" name="contact" maxlength="80" size="30">
     </
    td>
    </
    tr>
    <
    tr>
     <
    td valign="top">
      <
    label for="remarks">Remarks</label>
     </
    td>
     <
    td valign="top">
     <
    textarea  name="remarks" maxlength="50" ></textarea>
      
     </
    td>
    </
    tr>
    <
    tr>
     <
    td valign="top">
      <
    label for="designation">Designation </label>
     </
    td>
     <
    td valign="top">
      <
    input  type="text" name="designation" maxlength="50" size="50">
     </
    td>
    </
    tr>
    <
    tr>
     <
    td valign="top">
      <
    label for="email">E-mail </label>
     </
    td>
     <
    td valign="top">
     <
    input  type="text" name="email" maxlength="50" size="40">
       </
    td>
    </
    tr>
    <
    tr>
     <
    td colspan="2" style="text-align:center">
      <
    input type="submit" value="Submit"> <input type="reset" value="Reset"
     </
    td>
    </
    tr>
    </
    table>

     </
    form
    this is sendemail.php
    PHP Code:
    <?php
    session_start
    ();
    if(isset(
    $_POST['email'])) {
         
        
    // EDIT THE 2 LINES BELOW AS REQUIRED
        
    $email_to "-----------------l@gmail.com";
        
    $email_subject "Contact Details";
         
         
        function 
    died($error) {
            
    // your error code can go here
            
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo 
    "These errors appear below.<br /><br />";
            echo 
    $error."<br /><br />";
            echo 
    "Please go back and fix these errors.<br /><br />";
            die();
        }
         
        
    // validation expected data exists
        
    if(!isset($_POST['name']) ||
            !isset(
    $_POST['organisation']) ||
            !isset(
    $_POST['email']) ||
            !isset(
    $_POST['contact']) ||
            !isset(
    $_POST['designation']) ||
            !isset(
    $_POST['remarks'])) {
            
    died('We are sorry, but there appears to be a problem with the form you submitted.');       
        }
         
        
    $name $_POST['name']; 
        
    $organisation $_POST['organisation']; 
        
    $email $_POST['email']; 
        
    $contact $_POST['contact']; 
        
    $designation $_POST['designation']; 
        
    $remarks $_POST['remarks']; 
         
        
    $error_message "";
        
    $email_exp '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!
    preg_match($email_exp,$email)) {
        
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
      }
        
    $string_exp "/^[A-Za-z .'-]+$/";
      if(!
    preg_match($string_exp,$name)) {
        
    $error_message .= 'Name you entered does not appear to be valid.<br />';
      }
        if(
    strlen($remarks) < 2) {
        
    $error_message .= 'The Remarks you entered do not appear to be valid.<br />';
      }
      if(
    strlen($error_message) > 0) {
        
    died($error_message);
      }
        
    $email_message "Form details below.\n\n";
         
        function 
    clean_string($string) {
          
    $bad = array("content-type","bcc:","to:","cc:","href");
          return 
    str_replace($bad,"",$string);
        }
         
        
    $email_message .= "Name: ".clean_string($name)."\n";
        
    $email_message .= "Organisation: ".clean_string($organisation)."\n";
        
    $email_message .= "Contact No: ".clean_string($contact)."\n";
        
    $email_message .= "Email: ".clean_string($email)."\n";
        
    $email_message .= "Remarks: ".clean_string($remarks)."\n";
        
    $email_message .= "Designation: ".clean_string($designation)."\n";
         
         
    $headers 'From: '.$email."\r\n".
    'Reply-To: '.$email."\r\n" .
    'X-Mailer: PHP/' phpversion();
    @
    mail($email_to$email_subject$email_message$headers);  
    }
    ?>
    <!-- include your own success html here -->
     
    Thank you for contacting us. We will be in touch with you very soon.

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    unless you are specifing your own function called 'died()' somewhere I can see, you need to change all 2 instances of that to die().

    change

    PHP Code:
    'X-Mailer: PHP/' phpversion(); 
    to

    PHP Code:
    'X-Mailer: PHP/' phpversion() . "\r\n"
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi..

    Thank for your reply..

    But still the values of the form is not sent to the mail id

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OK, you said it wasnt working, I assumed that you were not getting the email !! Give me 5
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  5. #5
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    your script works fine, ive tried it on my server here and all is OK
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should i change the function died() to function die()??

  7. #7
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by danielbala View Post
    Should i change the function died() to function die()??
    Its not actually stopping the script from working here (surprisingly) but Id change it for the sake of correctness.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    iam trying to run in wamp server
    should i setup any mail server for testing the script \locally??

  9. #9
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    your server will need to have an SMTP server configured and running to test this script yes, PHP doesnt send the mail, it only passes it to the local SMTP server.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  10. #10
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    On this thread I suggested to use CRLF:
    http://www.sitepoint.com/forums/show...=1#post5110829

    Even though it did not solve that problem but maybe should try it here and see if it will work.

    This type of errors is due to send a line more than 1000 characters long:
    http://www.tech-pro.net/tcpip4.html
    http://mgrand.home.mindspring.com/mime.html

  11. #11
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Tom, its being run on Wamp ..... hence no mail
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  12. #12
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks. Next time I post, I better make sure to read every posts.


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
  •