pinceladasdaweb / simple-php-contact-form Goto Github PK
View Code? Open in Web Editor NEWA Simple Contact Form developed in PHP with HTML5 Form validation.
License: MIT License
A Simple Contact Form developed in PHP with HTML5 Form validation.
License: MIT License
"The input is not being sanitized, which can allow people to submit a name like "Bob\nCC: [email protected], [email protected]", etc, to use your contact form as a relay point. "
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
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)) {
link to demo in readme and project description line returns a 404 error
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:
When form is submitted if you try and refresh the page you get the prompt that the form will submit again. Any way around this?
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 ?
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; ?>
'from' => '' // A valid email where the domain should be the same when the form is hosted.
Is there an example?
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.
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.
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' ] ];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'
]
];`
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.
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.
I think you need to add something like this: http://blueashes.com/2013/web-development/html5-form-validation-fallback/
Since contact forms
It would be great if this could support captcha, maybe by adding secureimage https://www.phpcaptcha.org/
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
This problem is listed here: http://www.webdevdoor.com/wordpress/submitting-form-wordpress-redirects-404-page/
Write now the html form element is inside an index.php file. Is there anyway to extract it to a plain index.html file and still have the contact form work?
Any way to add Attachment hosted in same directory?? ?
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
steven@testy is obviously just fake data I entered into the form, but the same happens with a proper name/address.
Hi,
can you please correct the regular expression to validate email's at contact-form.js
Currently, i cannot use hyphen in my email address at domain side.
If you change that to working email validation then this is quite good form.
Thanks,
Ashish
I notice that there are not validation for the phone number
if ($name && $email && $emailIsValid && $subject && $message) {
// Send mail
}
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
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?
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
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..
The RegEx appears to only allow A-z 0-9 and _'s before the @ symbol, but I often use the format: [email protected] which is a valid email.
I suggest something like:
^[A-z0-9._%+-]+@[A-z0-9.-]+.[A-z]{2,4}$
(from http://www.regular-expressions.info/email.html)
Thanks.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.