0

Hi, My name is jai and I am trying to code a contact form in php all is going well but I am unable to get data in my email which I am filling in this form please help me. my php code is below

<?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'])); 

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

$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;
?>
7
Contributors
12
Replies
72
Views
2 Years
Discussion Span
Last Post by Ventech_IT
-1

thank you but it is not working can you look into this please its very urgent.

0

Can we see the form you are using to submit data to this script. Also Remove the @ and use error_reporting(E_ALL) and display_errors(1) so you can see if there are any errors. Also what does $success equal? can you add var_dump($success) just so we can see if it is true or false.

Edited by toxicandy

0

@jaiuriyal

Which is the value of $email_from? A GMail account? The From header MUST be an email address that you can authenticate against an SMTP server. If using a free hosting then this is not the issue, as they will replace the headers. The same if you set sendmail properly.

Here you have to set two headers From and Reply-To:

  • From with your email
  • Reply-To with the value of $_POST['email']

The thread I linked explains the issue and it is linked to another thread with more information. Please take time to understand how it works.

0

@toxicandy
this is my form in which I am trying to do this

<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>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>

when I am submiting the form I am getting this output in my email:

via sg2plcpnl0020.prod.sin2.secureserver.net

Name:

Email:

Subject:

Message:

-1

@toxicandy

please help me actully I am new in php and this is my urgent project thanks in advance

0

What are the results when you do var_dump($success), the text from the your comment back looked like it was the $body not the $success also depending on version of PHP you are using you can replace the trim(stripslashes($_POST['NAME'])); with filter_input(INPUT_POST, 'NAME', FILTER_SANITIZE_STRING);. For $email I would do filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);

1

Probably the php is having error in the line $subject = @trim(stripslashes($_POST['subject'])); where your form is not having the post for 'subject' area.

Votes + Comments
nice catch!
0

@toxicandy

I am replacing name and email input as you guided me but result remains the same.

0

thank you but it is not working can you look into this please its very urgent.

and

please help me actully I am new in php and this is my urgent project thanks in advance

Take time to read the first thread in the forum:

https://www.daniweb.com/web-development/php/threads/435023/read-this-before-posting-a-question

It states, amongst many other things:

Do not tell us how urgent your problem is. Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.

If you are still getting errors, post your updated code. We have no idea what it looks like, e.g. you may have introduced a typo.
In addition, when testing, try omitting @ as it suppresses error messages:

http://php.net/manual/en/language.operators.errorcontrol.php

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.