Beginner PHP email submit form

Hi guys. I am very new to PHP and have little or no knowledge at the moment. Currently I have a live site but would like to add a email submit form that would send the users information to a certain email and number of emails. A file submit option would be handy too.

I have tried a few pre made scripts and templates but just cant figure out how to make any of them work. I use Dreamweaver to code and manage my live site.

Below is a picture of the message I am getting in Dreamweaver and a link to the script I am using.

http://www.freecontactform.com/email_form.php

Php has a function called mail.
http://php.net/manual/en/function.mail.php

If you have a look around you can probably find a wrapper for it that allows files.

My suggestion would to use PHPMailer https://github.com/PHPMailer/PHPMailer this even gives you a small example on how to use it. You can do a lot with PHPMailer besides just sending plain emails and I think it will suit you needs.

My other suggestion is to throwout that script, for whenever I see tables I cringe. :smiley:

Here’s one good example of some good form designs with the html - link on how to create a form ->
https://www.sanwebe.com/2014/08/css-html-forms-designs
Google forms if you aren’t satisfied with that link, for there are many out there that should fit your need that don’t use tables. There’s nothing wrong using tables, but tables in my opinion are better for display data ( a lot of data really easily).

I would concentrate first on just the HTML/CSS portion of the form and that is where an IDE comes in handy. I would treat Dreamweaver simply as a glorified coding and HTML/CSS IDE and nothing more.

Here’s an example of a contact form on my page, the first thing I did was concentrate on the HTML/CSS portion (THIS IS ONLY AN EXAMPLE)
[php]<?php
require_once DIR . ‘/vendor/autoload.php’;
require_once ‘lib/includes/utilities.inc.php’;

use website_project\email\EmailData as Email;
use website_project\email\Contact as SendForm;

$submit = filter_input(INPUT_POST, ‘submit’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);

if (isset($submit) && $submit === ‘submit’) {
$first_name = filter_input(INPUT_POST, ‘first_name’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$last_name = filter_input(INPUT_POST, ‘last_name’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$name = $first_name . ’ ’ . $last_name;
$email = filter_input(INPUT_POST, ‘email’, FILTER_SANITIZE_EMAIL);
$message = filter_input(INPUT_POST, ‘comment’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$topic = filter_input(INPUT_POST, ‘reason’, FILTER_SANITIZE_SPECIAL_CHARS);

/* Spambot check this uses a hidden Captcha technique */
$spambot = filter_input(INPUT_POST, 'subject', FILTER_SANITIZE_SPECIAL_CHARS);


$send = new SendForm(new Email($name, $email, $topic, $message, $spambot));
if (!$send->sendMail()) {
    if (!$send->getName()) {
        $nameError = $send->getNameError();
    } else {
        $displayName = $send->getName();
    }

    if (!$send->getEmail()) {

        $emailError = $send->getEmailError();
    } else {
        $displayEmail = $send->getEmail();
    }
    if (!$send->getMessage()) {
        $messageError = $send->getMessageError();
    } else {
        $displayMessage = $send->getMessage();
    }
} else {
    $success = 'Email successfully sent!';  // Set the success message if message was sent correctly:
}

}

require_once ‘lib/includes/header.inc.php’;
?>

Contact Form First Name Last Name Email Address
Leave blank
comment pricing order info
        <label class="textareaLabel" for="message">Message</label>
        <textarea id="message" name="comment" placeholder="Enter message here..."></textarea>
        <!-- Display the success message if email was sent -->
        <?php echo isset($success) ?'<label>' . $success . '</label>': NULL; ?>
        <input type="submit" name="submit" value="submit">
    </fieldset>
</form> 
<article class="span6 bg-color">
    <div class="contact-info-block">
         <h3>Contact Details</h3>
         <ul class="contact-info">
         <li class="phone"><a href="tel:1-734-748-7661">(734) 748-7661</a></li>
        <li class="mail"><a href="mailto:[email protected]">[email protected]</a></li>
        <li class="twitter"><a href="http://twitter.com/intent/tweet?screen_name=strider64">[member=57087]Strider64[/member]</a></li>
        </ul>
    </div>
</article>
> <?php require_once 'lib/includes/footer.inc.php'; [/php]

and you can see it in action if you click on my signature link below:

I will be glad to help with the design of the form (as well as the coding) as I’m sure other will be to if you decide to go this route, just shows us what you have come up with.

[php] $submit = filter_input(INPUT_POST, ‘submit’, FILTER_SANITIZE_FULL_SPECIAL_CHARS);

if (isset($submit) && $submit === ‘submit’) {[/php]

For real?

Sponsor our Newsletter | Privacy Policy | Terms of Service