2
votes

I have a contact form on a website where the user can send message to the website owner. the contact form for it is

<form class="form" id="form1" action="send_form_email.php" method="post">
    <p class="name">
        <input name="name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Name" id="name" />
    </p>

    <p class="phone">
        <input name="phone" type="text" class="validate[required,custom[email]] feedback-input" id="phone" placeholder="Phone Number" />
    </p>

    <p class="email">
        <input name="email" type="text" class="validate[required,custom[email]] feedback-input" id="email" placeholder="Email" />
    </p>

    <p class="businessname">
        <input name="business_name" type="text" class="validate[required,custom[onlyLetter],length[0,100]] feedback-input" placeholder="Business Name" id="name" />
    </p>

    <p class="text">
        <textarea name="comment" class="validate[required,length[6,300]] feedback-input" id="comment" placeholder="Comment"></textarea>
    </p>

    <div class="submit">
        <input type="submit" name="submit" value="Submit!"  id="button-blue"/>
        <div class="ease"></div>
    </div>
</form>

the coding for send_form_email.php is:

<?php 
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$business_name = $_POST['business_name'];
$comment = $_POST['comment'];

$from = 'From: website.com'; //url of contact form or website
$to = '[email protected]'; //my email id
$subject = 'Customer Inquiry';
$body = "From: $name\n Phone: $phone\n E-Mail: $email\n Business Name: $business_name\n Message:\n $message";

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html\r\n";
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
header( "Location: index.html" );
?>

the problem is that it is showing an error on line 6 (i.e $comment = $_POST['comment'];) saying Parse error: syntax error, unexpected T_STRING in /nfs/c11/h01/mnt/193678/domains/website.com/html/admin/send_form_email.php on line 6

EDIT: 1

I have removed the error it was due to some server problem.. but now the error is that when a mail is being sent to the admin, the message in the mail is blank, i wish to receive name, email, phoneno, business and comment in the mail

1
This error may occur due to missing semicolon, missing quotes etc. In this shared code I can't find any such errors.Jenz
@Arif_suhail_123 this is my full codesam
@sam..I executed your code in my localhost but I am not getting the error you have mentioned.Jenz
Where is your $message variable ?Ahmad Samilo
Right..seems there is no error is this script.sandip patil

1 Answers

1
votes

Change your $body to message like this

$message = "From: $name\n Phone: $phone\n E-Mail: $email\n Business Name: $business_name\n Message:\n ";