Page 1 of 1

URGENT CONTACT FORM

Posted: Sat Mar 19, 2016 4:15 am
by MartinEbner
Hi,

Please can a PHP Guru support me in a basic contact form? Below is the code that is triggered by my HTML form:

Code: Select all

<?php
$name       = @trim(stripslashes($_POST['name'])); 
$from       = @trim(stripslashes($_POST['email'])); 
$subject    = @trim(stripslashes($_POST['subject'])); 
$message    = @trim(stripslashes($_POST['message'])); 
$to   		= 'sales@motioneyes.co.uk';//replace with your email

$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();

mail($to, $subject, $message, $headers);

die;


Thanks,
Martin

Re: URGENT CONTACT FORM

Posted: Sat Mar 19, 2016 5:17 am
by MartinEbner
Can someone help, please?

Re: URGENT CONTACT FORM

Posted: Sat Mar 19, 2016 8:34 am
by Celauran
Maybe start by telling us what's wrong?

Re: URGENT CONTACT FORM

Posted: Sat Mar 19, 2016 10:52 am
by MartinEbner
Hi,

That would be a good start - my bad!

The form itself will not work. IE; a visitor completes the form and submits but it will not send to the nominated email address.

Thanks,

Re: URGENT CONTACT FORM

Posted: Sat Mar 19, 2016 4:08 pm
by Christopher
So maybe post the HTML form, so we can what is being sent? And I assume by "IE" you mean i.e., and not Internet Explorer?

Re: URGENT CONTACT FORM

Posted: Sun Mar 20, 2016 1:26 pm
by MartinEbner
Hi Christopher,

That's right, not Internet Explorer and here is the HTML code:

Code: Select all

 <form id="main-contact-form" name="contact-form" method="post" action="sendemail.php">
                            <div class="form-group">
                                <input type="text" name="name" class="form-control" required="required" placeholder="Name">
                            </div>
                            <div class="form-group">
                                <input type="email" name="email" class="form-control" required="required" placeholder="Email Id">
                            </div>
                            <div class="form-group">
                                <textarea name="message" id="message" required class="form-control" rows="8" placeholder="Your text here"></textarea>
                            </div>                        
                            <div class="form-group">
                                <input type="submit" name="submit" class="btn btn-submit" value="Submit">
                            </div>
                        </form>

Thank you.

Re: URGENT CONTACT FORM

Posted: Sun Mar 20, 2016 6:23 pm
by Christopher
So my first question would be, have you checked the error logs?

Next, does the email() function work as configured. To test, try something like this (filling in the names and email addresses):

Code: Select all

$headers = array("From: some name <some email address>");
$result = mail('known email address', 'Test Email', 'This is a test email.', $headers);
echo "result=$result<br>";
If email() works then maybe add some debug to you script:

Code: Select all

echo "to=$to<br>subject=$subject<br>message=$message<br>";
echo "headers=<pre>" . print_r($headers, 1) . "</pre>";
$result = mail($to, $subject, $message, $headers);
echo "result=$result<br>";
[/syntax]

Re: URGENT CONTACT FORM

Posted: Tue Mar 22, 2016 2:28 am
by MartinEbner
Hi Chris,

Sorry for the ignorance - I am very new to PHP. This said, I was informed that this code was almost a 'plug and play' piece but it is still not working. I have spoken with my domain host and they have confirmed there are no server issues so it must be an issue with the code.

I think I ought to commision someone to build a working code for me because this is dumbfounding me.

Regards,

Re: URGENT CONTACT FORM

Posted: Tue Mar 22, 2016 12:17 pm
by Christopher
Have you tried creating a php file from the first piece of code I posted above, adding real email addresses, and running it? That would let you know if email is working at all -- which may be the problem, not your code.

Or can you add the lines from the second piece of code I posted above to your script? That would give you some debug information.