SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Wizard
    Join Date
    Jul 2006
    Location
    New Zealand
    Posts
    1,300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php mail contact form not working

    Hi all

    I am in the middle of setting up a php contact form for a client of mine and i am having problems reading the email upon when it arrives in my inbox on my hotmail account as it displays a blank From address in the address field in from field and since i am using windows live mail not sure what i did wrong heres a snippet of my php code.

    PHP Code:
    $subject=$_POST['sub'];
        $message=$_POST['mess'];
        $ctype=$_POST['ctype'];
        $contact=$_POST['contact'];
        $capt=$_POST['capt'];
        if($sub="")
        {
            ?>
            <script type="text/javascript">
                alert('The Subject is Empty please re-enter the subject.')
            </script>
            <?    
        
    }
        else
        {
            
    //
            
    if($msg="")
            {
                
    //
                
    ?>
                    <script type="text/javascript">
                        alert('The Message is Empty please re-enter the Message.')
                    </script>
                <?    
                
    //
            
    }
            else
            {
                
    //
                
    if($contact="")
                {
                    
    ?>
                    <script type="text/javascript">
                        alert('The Contact Method is Empty please re-enter the Way you wish to be contacted..')
                    </script>
                    <?    
                
    }
                else
                {
                    if(
    $capt==$p)
                    {
                        
    $to "demonhunterds@hotmail.com";
                        if(
    $ctype="email")
                        {
                            
    //
                            
    $headers "From".$contact."";
                            echo 
    $headers;
                            
    /*mail($to,$subject,$message,$headers);
                            echo "Mail Sent,We will respond to you asap.";
                            *///
                        
    }
                        else if(
    $ctype="phone")
                        {
                            
    $c="You can contact them on $contact";
                            
    mail($to,$subject,$message,$c);
                            echo 
    "Mail Sent,We will respond to you asap.";
                        }
                        else if(
    $ctype="mobile")
                        {
                            
    $c="You can contact them on $contact";
                            
    mail($to,$subject,$message,$c);
                            echo 
    "Mail Sent,We will respond to you asap.";
                        }
                        else if(
    $ctype="fax")
                        {
                            
    $c="You can contact them on $contact";
                            
    mail($to,$subject,$message,$c);
                            echo 
    "Mail Sent,We will respond to you asap.";
                        }
                    }
                    else
                    {
                        
    ?>
                        <script type="text/javascript">
                            alert('The Captcha Field is Empty please re-enter the  word  again.')
                        </script>
                        <?
                    
    }
                }
                
    //
            
    }
            
    //
        
    }
    Also on the other end is there any other way apart from captcha should i make my php contact form more secure from sending spam and what not?

    Any help would be good,

    Thanks,William

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There fourth parameter to mail() is additional headers.

    "You can contact them on $contact" is not a standard header. I think you meant to append that to the message, not put it in the headers.

    You want something like "From: me@example.com"

  3. #3
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An easy way to get round this is to 'error detect'. Much better, you wont end up with loads of nested if's which prevent nice easy reading of code!

    PHP Code:
    $msgStack = array();
    if(
    $case=false){
       
    $msgStack[] = 'error...';
    }
    //then test if there were any errors
    if(count($msgStack>0)){
       foreach(
    $msgStack as $msg){
          echo 
    $msg.'<br>';
       }
    } else {
       
    mail(...);


  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    update the code this way:
    PHP Code:
    $headers "From: you@yourwebsite.com\r\n";
    ...
    ...
    mail($to,$subject,$message,$headers ); 
    The following pages might help:
    HTML contact form with CAPTCHA

    PHP based email contact form

  5. #5
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It may not be the problem but you have done what I do all the time.

    if($contact="")

    should be

    if($contact=="")



    Keith


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
  •