URGENT CONTACT FORM

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
MartinEbner
Forum Newbie
Posts: 5
Joined: Sat Mar 19, 2016 4:12 am

URGENT CONTACT FORM

Post 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
MartinEbner
Forum Newbie
Posts: 5
Joined: Sat Mar 19, 2016 4:12 am

Re: URGENT CONTACT FORM

Post by MartinEbner »

Can someone help, please?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: URGENT CONTACT FORM

Post by Celauran »

Maybe start by telling us what's wrong?
MartinEbner
Forum Newbie
Posts: 5
Joined: Sat Mar 19, 2016 4:12 am

Re: URGENT CONTACT FORM

Post 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,
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: URGENT CONTACT FORM

Post 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?
(#10850)
MartinEbner
Forum Newbie
Posts: 5
Joined: Sat Mar 19, 2016 4:12 am

Re: URGENT CONTACT FORM

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: URGENT CONTACT FORM

Post 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]
(#10850)
MartinEbner
Forum Newbie
Posts: 5
Joined: Sat Mar 19, 2016 4:12 am

Re: URGENT CONTACT FORM

Post 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,
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: URGENT CONTACT FORM

Post 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.
(#10850)
Post Reply