PHP send mail error

Discussion in 'PHP' started by muchochiz, Dec 27, 2010.

  1. #1
    i am having some problem with my PHP form . I have created everything and its posting the details to my mailbox the problem however is that in the message area all it shows is $text , it doesn't show what the visitor typed into that area all it shows is $text

    here is the form

    here is the PHP

    please is there something / a code wrong here ?
     
    muchochiz, Dec 27, 2010 IP
  2. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #2
    You have run type="submit" and value="" together.
    
    <input type="submit"value="send your inquiry" />
    
    Code (markup):

    You should add error checking to make sure the values are being sent, and to see if they are empty. like this:


    
    <?php
    $error = 0;
    if(isset($_POST['username'])){
        $name = $_POST['username'];
    }else{
         echo "Please enter username";
         $error++;
    }
    
    if(isset($_POST['email'])){
         $email = $_POST['email'];
    }else{
         echo "Please enter email";
         $error++;
    }
    
    if(isset($_POST['inquiry'])){
         $text = $_POST['inquiry'];
    }else{
         echo "Please enter inquiry";
         $error++;
    }
    
    
    
    //To, Subject, Message, Header
    
    if($errors > 0){
         echo "Mail not sent! Please correct the above problems and try again.");
    }else{
         mail('myemail@mywebsite.com','Inquiry',$text,'From: '. $name .'<' . $email . '>');
         echo "Your message has been sent";
         header('location: step3.html')
    }
    
    ?> 
    
    
    Code (markup):
     
    Last edited: Dec 27, 2010
    shofstetter, Dec 27, 2010 IP
  3. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #3
    I messed up the code in my previous post. I didn't realize you had spanned the mail function across 2 lines :D

    Try the below it will be more readable. Oh and you were missing the 'l' in mail(). I got your pm. Try to check $text right before you use the mail() function like this:
    echo $text; just to see if it is set. If it prints the text then it should be sending it in the email.

    If it does print the content $text, but it doesn't show in the email try setting the text manual in the mail function to see if it will send.

    like: mail("my@email.com","Test Subject","Test Message");

    if you still get an email without a message body check the config in the php.ini to make sure it is setup to work correctly with you servers mail program (postfix,sendmail,exim,etc).


    
    <?php
    $to      = 'myemail@mywebsite.com';
    $subject = 'Inquiry';
    $message = $text;
    $headers = 'From: ".$name."<".$email.">"."\r\n";
    
    
    mail($to, $subject, $message, $headers);
    
    ?>
    
    Code (markup):
     
    shofstetter, Dec 27, 2010 IP