Giter Site home page Giter Site logo

pinceladasdaweb / simple-php-contact-form Goto Github PK

View Code? Open in Web Editor NEW
371.0 31.0 153.0 59 KB

A Simple Contact Form developed in PHP with HTML5 Form validation.

License: MIT License

JavaScript 30.05% PHP 56.85% Shell 1.79% Dockerfile 11.32%
php contact-form

simple-php-contact-form's Introduction

Simple PHP Contact Form

A Simple Contact Form developed in PHP with HTML5 Form validation. Has a fallback in JavaScript for browsers that do not support HTML5 form validation.

Containerized with Alpine based container

Using techniques from https://github.com/hardware/rainloop

The container adds ssmtp so you can set up a working config in /etc/ssmtp/ for the outgoing mail.

Download

You can download the latest version or checkout all the releases here.

Requirements

  • PHP >=5.4

How to use?

Open the config.php config.php file and fill with your informations.

<?php

return [
    'subject' => [
        'prefix' => '[Contact Form]'
    ],
    'emails' => [
        'to'   => '', // Email address to receive emails via the form.
        'from' => '' // A valid email address - the domain should be the same as where the form is hosted.
    ],
    'messages' => [
        'error'   => 'There was an error sending, please try again later.',
        'success' => 'Your message has been sent successfully.'
    ],
    'fields' => [
        'name'     => 'Name',
        'email'    => 'Email',
        'phone'    => 'Phone',
        'subject'  => 'Subject',
        'message'  => 'Message',
        'btn-send' => 'Send'
    ]
];

Browser Support

IE Chrome Firefox Opera Safari
IE 9+ ✔ Latest ✔ Latest ✔ Latest ✔ Latest ✔

Contributing

Check CONTRIBUTING.md for more information.

History

Check Releases for detailed changelog.

License

MIT

simple-php-contact-form's People

Contributors

dhyegocalota avatar ksylvan avatar marquinhusgoncalves-zz avatar matheusgontijo avatar moox avatar pinceladasdaweb avatar sidneygijzen avatar thedavedavies avatar wbruno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simple-php-contact-form's Issues

PHP Parse Error

Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /home/a3416167/public_html/contact-form/index.php on line 10
The code on line ten is
use Helpers\Config; use SimpleMail\SimpleMail;
Why is this arising?

Works on some servers, but not others

Just quickly, I have noticed that this fantastic form works on my testing server for the clients I use it for, but when I send the files to their live servers, it's a bit of a 50/50 whether the form actually works.

Is there some kind of server setting dependencies we should be looking out for?

Thank for a great bit of code!

// Rob

Where do I enter email information?

Could you please show me an example is my bolded email correct?
`<?php

return [
'subject' => [
'prefix' => '[Contact Form]'
],
'emails' => [
'to' '[email protected]' => '',
'from' => ''
],
'messages' => [
'error' => 'There was an error sending, please try again later.',
'success' => 'Your message has been sent successfully.'
],
'fields' => [
'name' => 'Name',
'email' [email protected] => 'Email',
'phone' => 'Phone',
'subject' => 'Subject',
'message' => 'Message',
'btn-send' => 'Send'
]
];`

Attachment

Any way to add Attachment hosted in same directory?? ?

what is "from" field?

'from' => '' // A valid email where the domain should be the same when the form is hosted.

Is there an example?

Senders IP addr

did anyone tried implementing php functionality to track sender's IP addr?

<input type="hidden" name="IP Address" class="form-control" id="form-name" value="<?php echo $_SERVER['REMOTE_ADDR'] ?>">

xxxxxxxxxx
update
xxxxxxxxxx

nvm got it working

CONTACT FORM DONT WORK

When I click on send shows the message that has been sent but on my email is not on the mailbox. I changed the email to

No validation for the phone number

I notice that there are not validation for the phone number

if ($name && $email && $emailIsValid && $subject && $message) {
    // Send mail
}

Possible internationalization?

Hi,

I wonder if it's possible to make the script responsive to browser's language setting?
Because I'm not particularly a PHP programmer, I would like to now:

  • If such pull request would be welcome from my side whenever properly implemented,
  • Is it difficult and where to start? It would be also good to change the input's "placeholder" arg as shown below because some browsers (i.e. Mozilla) show them

in18

Recebimento

Implementei o Contact Form em meu site e fazendo os testes de envio da minha máquina em todos os navegadores o e-mail chega perfeitamente, porém se eu peço para qualquer outra pessoa enviar um contato o e-mail não chega, será que é algum bug ou erro de implementação em meu site?
Todo o código esta em https://github.com/marquinhusgoncalves/site-stephannieprint

Não estou recebendo os emails.

Acredito estar tudo nos conformes. Poderia por favor verificar algo que não encontrei de errado?

$subjectPrefix = '[Contato via Site]';
$emailTo = '[email protected]';

if($_SERVER['REQUEST_METHOD'] == 'POST') {
  $name    = stripslashes(trim($_POST['form-name']));
  $email   = stripslashes(trim($_POST['form-email']));
  $tel     = stripslashes(trim($_POST['form-tel']));
  $subject = stripslashes(trim($_POST['form-subject']));
  $message = stripslashes(trim($_POST['form-message']));
  $pattern  = '/[\r\n]|Content-Type:|Bcc:|Cc:/i';

  if (preg_match($pattern, $name) || preg_match($pattern, $email) || preg_match($pattern, $subject)) {
    die("Header injection detected");
  }

  $emailIsValid = preg_match('/^[^0-9][A-z0-9._%+-]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/', $email);

  if($name && $email && $emailIsValid && $subject && $message){
    $subject = "$subjectPrefix $subject";
    $body = "Nome: $name <br /> Email: $email <br /> Mensagem: $message";

    $headers  = 'MIME-Version: 1.1' . PHP_EOL;
    $headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL;
    $headers .= "From: $name <$email>" . PHP_EOL;
    $headers .= "Return-Path: $emailTo" . PHP_EOL;
    $headers .= "Reply-To: $email" . PHP_EOL;
    $headers .= "X-Mailer: PHP/". phpversion() . PHP_EOL;

    mail($emailTo, $subject, $body, $headers);
    $emailSent = true;
  } else {
    $hasError = true;
  }
}
?>

E aqui o formulário:

```<?php if(!empty($emailSent)): ?>
                  <div class="col-md-6 col-md-offset-3">
                    <div class="alert alert-success text-center">Sua mensagem foi enviada com sucesso.</div>
                  </div>
                <?php else: ?>
                  <?php if(!empty($hasError)): ?>
                    <div class="col-md-5 col-md-offset-4">
                      <div class="alert alert-danger text-center">Houve um erro no envio, tente novamente mais tarde.</div>
                    </div>
                  <?php endif; ?>

                  <!-- Form Section -->
                  <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" id="contact-form" class="form-horizontal" role="form" method="post">
                    <div class="four columns">
                      <label for="name" class="control-label">Nome:</label>
                      <input type="text" class="form-control required" id="form-name" name="form-name" placeholder="Ex: José da Silva" />

                      <label for="assunto" class="control-label">Assunto:</label>
                      <input type="text" class="form-subject required" id="form-subject" name="form-subject" placeholder="Ex: Retorno, CashBack" />
                    </div>

                    <div class="eight columns">
                      <div class="row">

                        <div class="six columns">
                          <label for="email" class="control-label">Email:</label>
                          <input type="email" class="u-full-width required" id="form-email" name="form-email"  placeholder="Ex: [email protected]">
                        </div>

                        <div class="six columns">
                          <label for="tel" class="control-label">Telefone:</label>
                          <input type="tel" class="u-full-width" id="form-tel" name="form-tel" placeholder="(88) 9989-9989">
                        </div>

                      </div>

                      <label for="mensagem" class="control-label">Mensagem: </label>
                      <textarea name="form-message" id="form-message" class="u-full-width required" rows="4"></textarea>
                      <input type="submit" class="button u-pull-right" value="Enviar">

                    </div>
                  </form>
                  <!-- End Form -->
                <?php endif; ?>

Doesn't work with Yahoo or AOL?

I've been using this for awhile now and was just made aware of this issue. If someone with a Yahoo or AOL email address fills out the form and sends, nothing is actually sent.

Found various things related to this:

http://admindaily.com/form-submissions-delivery-failure-yahoo-aol-email.html

https://discussion.dreamhost.com/thread-135041.html

And various others. Anyone else run into this issue? Looks like it just needs to be changed to not send "from" the address they put, but a "no-reply" address instead.

'from' field set as form field value, sent with 'to' address twice

Hi,

I have a strange issue. I've uploaded the project folder untouched except for entering the from and to in the config. In testing the form, the resulting email has two problems. Firstly, the 'from' address is not the address I set, on my domain, it's whatever I enter in the form. Secondly it's being sent to the 'to' address twice. The latter is not really too much of a problem but obviously the former is.

The to address is just my gmail. Sent with PHP 7.1.0

firefox_2017-05-29_18-23-36

steven@testy is obviously just fake data I entered into the form, but the same happens with a proper name/address.

More input fields

Hi just find out for this gem , but i have trouble making it work with more input fields i want to add 2 more but i do not find where to implement them to email send.
Can you help.

smtp; 550 Messages should have one or no To headers, not 2.

Hello Pedro,
I treid your work, but I get the error message and no email was submitted. I looked at the source code of the sended email and realy there are two entries of "To:" in the source. The first is without any mailaddress, the second with the mailaddress. I think that causes the error.
Here is a cut out of the source wth the two "To:"

To: 
Subject: =?UTF-8?B?TmFocmljaHQgenVtIEV2ZW50OiAgVGhlIEJlZSBXaWdzLCBGcmVpdGFnLCAyMi4gQXByaWwgMjAyMg==?=
X-PHP-Originating-Script: 10321:SimpleMail.class.php
MIME-Version: 1.0
To: <[email protected]>
Date: Tue, 05 Apr 2022 02:26:33 +0200

Can you please fix it. Or any one other has a suggestion for me to fix this.
Thanks

PHP8 support

It seems that PHP 7.4 is the latest version that this works in. PHP8 gets the following error, and doesn't send the mail:

[04-Mar-2021 16:53:28 UTC] PHP Warning: Attempt to read property "success" on null in public_html/xxx/index.php on line 73

This has to do with the Google Recaptcha portion of the code, where it verifies the secret key. I don't know PHP, so that's about as much I can help with..

From address is same as sender address

Confused. Why is the from address set to the sender address?

Shouldn't this:

$header  .= 'From: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->sender_email . '>' . PHP_EOL;
$header  .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->sender_email . '>' . PHP_EOL;

be more like this:

$header  .= 'From: ' . $this->from . PHP_EOL;
$header  .= 'Reply-To: =?UTF-8?B?' . base64_encode($this->sender) . '?= <' . $this->sender_email . '>' . PHP_EOL;

Sorry if i've missed something.

Send a confirmation email

Hello,

I would like to send a confirmation email to the people that use the contact form to say thank you and that I'll contact them back asap.

How hard would it be to implement that?

Anyone can help me with that?

Thanks in advance for the help.

Error return

Hey,

I tried your code on localhost and it works good, but when i put it online i have an error

Parse error: syntax error, unexpected '[' in /home/loicscia/www/config/config.php on line 4

Can you help me please ?

Vanilla js version has a typo

if (preg_match($pattern, $name) || preg_match($pattern, $email) || preg_match($pattern, $assunto)) {

should be

if (preg_match($pattern, $name) || preg_match($pattern, $email) || preg_match($pattern, $subject)) {

All messages go to spam...

Is there an issue? This form otherwise works wonderfully! here is my config:

[ 'prefix' => '[Contact Form]' ], 'emails' => [ 'to' => '[email protected]', 'from' => '' ], 'messages' => [ 'error' => 'There was an error sending, please try again later.', 'success' => 'Your message has been sent successfully.' ], 'fields' => [ 'name' => 'Name', 'email' => 'Email', 'phone' => 'Phone', 'subject' => 'Subject', 'message' => 'Message', 'btn-send' => 'Send' ] ];

demo link broken

link to demo in readme and project description line returns a 404 error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.