Contact Form details not shown in email

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xxshadowxx
Forum Newbie
Posts: 3
Joined: Mon Sep 07, 2015 4:49 pm

Contact Form details not shown in email

Post by xxshadowxx »

Hi All,

I would appreciate if someone can assist me with the php script as my email cannot receive the details in the contact form in html. Below is the coding for my html and php.

HTML:

<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="row-fluid">
<div class="span5">
<label>First Name*</label>
<input type="text" class="input-block-level" required="required" placeholder="Your First Name" value="">
<label>Last Name*</label>
<input type="text" class="input-block-level" required="required" placeholder="Your Last Name" value="">
<label>Email Address*</label>
<input type="email" class="input-block-level" required="required" placeholder="Your email address" value="">
</div>
<div class="span7">
<label>Telephone Number*</label>
<input type="tel" class="input-block-level" required="required" placeholder="Your telephone number" value="">
<label>Message*</label>
<textarea name="message" id="message" required="required" class="input-block-level" rows="15"></textarea>
</div>

</div>
<button type="submit" value="submit" class="btn btn-primary btn-large pull-right">Send Message</button>

PHP:

<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);

$first_name = @trim(stripslashes($_POST['first_name']));
$last_name = @trim(stripslashes($_POST['last_name']));
$email = @trim(stripslashes($_POST['email']));
$message = @trim(stripslashes($_POST['message']));

$email_from = $email;
$email_to = 'example@gmail.com';

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

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

echo json_encode($status);
die;


Awaiting for advice.

Yours Sincerely,
xxshadowxx
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Contact Form details not shown in email

Post by social_experiment »

[text]
<input type="text" class="input-block-level" required="required" placeholder="Your First Name" value="">
//
<input type="text" name="first_name" class="input-block-level" >
[/text]
You need a name attribute in your html code;

Code: Select all

<?php
 $first_name = @trim(stripslashes($_POST['first_name']));
 // php is looking for this value but doesn't find it in the $_POST array
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
xxshadowxx
Forum Newbie
Posts: 3
Joined: Mon Sep 07, 2015 4:49 pm

Re: Contact Form details not shown in email

Post by xxshadowxx »

Hi All, I have amended accordingly.

But the message still cannot be sent out. Am I missing something?

HTML:

<section id="contact-page" class="container">
<div class="row-fluid">

<div class="span8">
<h4>Contact Form</h4>
<div class="status alert alert-success" style="display: none"></div>

<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="row-fluid">
<div class="span5">
<label>First Name*</label>
<input type="text" name="first_name" class="input-block-level" required="required" placeholder="Your First Name" value="" method="post">
<label>Last Name*</label>
<input type="text" name="last_name" class="input-block-level" required="required" placeholder="Your Last Name" value="" method="post">
<label>Email Address*</label>
<input type="email" name="email_address" class="input-block-level" required="required" placeholder="Your email address" value="" method="post">
</div>
<div class="span7">
<label>Telephone Number*</label>
<input type="tel" name="telephone_number" class="input-block-level" required="required" placeholder="Your telephone number" value="" method="post">
<label>Message*</label>
<textarea name="message" name="message" id="message" required="required" class="input-block-level" rows="15" method="post"></textarea>
</div>

</div>
<button type="submit" value="submit" class="btn btn-primary btn-large pull-right">Send Message</button>


PHP:

<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);

$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_address = $_POST['email_address']; // required
$telephone_number = $_POST['telephone_number'] // required
$message = $_POST['message']; // required

$email_from = $email;
$email_to = 'example@gmail.com';

$body = 'First Name: ' . $first_name . "\n\n" . 'Last Name: ' . $last_name . "\n\n" . 'Email Address: ' . $email_address . "\n\n" . 'Telephone Number: ' . $telephone_number . "\n\n" . 'Message: ' . $message . "\n\n" .;

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

echo json_encode($status);
die;

Do I need an additional script or something in order to send out the message in the contact form?

Regards,
xxshadowxx
Last edited by xxshadowxx on Tue Sep 08, 2015 10:59 am, edited 1 time in total.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Contact Form details not shown in email

Post by social_experiment »

are you receiving an error message?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply