Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an HTML form on a web page with the purpose of the user to send an email with some information, e-mail is sent but the information from the form fields is not sent.

The HTML form:

HTML
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
                    <div class="col-sm-5 col-sm-offset-1">
                        <div class="form-group">
                            <label>Name *</label>
                            <input type="text" name="name" class="form-control" required="required">
                        </div>
                        <div class="form-group">
                            <label>Email *</label>
                            <input type="email" name="email" class="form-control" required="required">
                        </div>
                        <div class="form-group">
                            <label>Phone</label>
                            <input type="number" class="form-control">
                        </div>
                        <div class="form-group">
                            <label>Company Name</label>
                            <input type="text" class="form-control">
                        </div>                        
                    </div>
                    <div class="col-sm-5">
                        <div class="form-group">
                            <label>Subject *</label>
                            <input type="text" name="subject" class="form-control" required="required">
                        </div>
                        <div class="form-group">
                            <label>Message *</label>
                            <textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
                        </div>                        
                        <div class="form-group">
                            <button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
                        </div>
                    </div>
                </form> 


The php script:

<?php

    header('Content-type: application/json');
	$status = array(
		'type'=>'success',
		'message'=>'Thank you for contact us. As early as possible  we will contact you '
	);

    //$name = @trim(stripslashes($_POST['name'])); 
    //$email = @trim(stripslashes($_POST['email'])); 
    //$subject = @trim(stripslashes($_POST['subject'])); 
    //$message = @trim(stripslashes($_POST['message'])); 

    $name = trim(stripslashes(var_dump($_POST['name'])));
    $email = trim(stripslashes(var_dump($_POST['email']))); 
    $subject = trim(stripslashes(var_dump($_POST['subject']))); 
    $message = trim(stripslashes(var_dump($_POST['message']))); 

    $email_from = $email;
    $email_to = 'goncalopalma22@gmail.com';//replace with your email

    $body = 'Name: ' . $name . "\r\n" . 'Email: ' . $email . "\r\n" . 'Subject: ' . $subject . "\r\n" . 'Message: ' . $message;

    $success = mail($email_to, $body, 'From: <'.$email_from.'>');

    echo json_encode($status);
    die;
?>


What I have tried:

A few different versions of the php script.
Posted
Comments
NightWizzard 10-Mar-16 13:24pm    
Did you try a simple
$name = $_POST['name'];
var_dump will display a structure and can't be used to assign it's output to a variable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900