Simple form mailer help

Discussion in 'PHP' started by webdesignguru, Oct 16, 2010.

  1. #1
    Ive need help making a form for a contact form,ive got the html side sorted but whenever i make a php form to actually post the information to my email i recieve an email but no message ?
    Can anyone help me out as to what the correct php code should be ?

    Heres the html :
    <form class="cmxform" id="contactForm" method="POST" action="mailer.php">
    					<fieldset>
    						<p>
    							<label for="cname">Name</label>
    							<input type="text" name="cname" class="required" value="" id="cname" />
    						</p>
    						<p>
    							<label for="cemail">Email</label>
    							<input type="text" name="cemail" class="required email" value="" id="cemail" />
    						</p>
    						<p>
    							<label for="csubject">Website</label>
    							<input type="text" name="csubject" class="required" value="" id="csubject" />
    						</p>
    						<p>
    							<label for="ccomment">Message</label>
    							<textarea cols="30" rows="10" class="required" name="ccomment" id="ccomment"></textarea>
    						</p>
    					</fieldset>
    					<p><button class="submit" type="submit">Send</button></p>
    				</form>
    HTML:
    Thanks in advance
     
    webdesignguru, Oct 16, 2010 IP
  2. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #2
    Can you show us your PHP code for this? From what it looks like, there is no issues with the form, only how the PHP is handling the data that you are passing to it
     
    Grit., Oct 16, 2010 IP
  3. webdesignguru

    webdesignguru Active Member

    Messages:
    233
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #3
    <?php
    // Contact subject
    $subject ="$csubject"; 
    // Details
    $message="$ccomment";
    
    // Mail of sender
    $mail_from="$cemail"; 
    // From 
    $header="from: $cname <$mail_from>";
    
    // Enter your email address
    $to ='test@test.com';
    
    $send_contact=mail($to,$subject,$message,$header);
    
    // Check, if message sent to your email 
    // display message "We've recived your information"
    if($send_contact){
    echo "We've recived your contact information";
    }
    else {
    echo "ERROR";
    }
    ?>
    PHP:
     
    webdesignguru, Oct 16, 2010 IP
  4. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #4
    Make it into:

    I have assumed you've not used the $_POST to get the data first from the snippet you provided

    It is also worth implementing some level of data cleansing to prevent any malicous use of the form
     
    Grit., Oct 16, 2010 IP
  5. betaturn

    betaturn Peon

    Messages:
    273
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    add in mailer.php just after <?php

    foreach($_GET AS $key => $value) {
    ${$key} = $value;
    }
    foreach($_POST AS $key => $value) {
    ${$key} = $value;
    }
     
    betaturn, Oct 17, 2010 IP