I am totally new to PHP and I am just trying to block spam in my forms. I have
figured out how to do a honeypot (url field) with the following code that
blocks 90% of the spam - but this one irritating emailer gets through
(let's call them redacted#example.com). I would like to write one line of
code in my form that just says if the email field is filled out with the text
'redacted#example.com', then don't pass the form through. Is there anyone who can help me do this?
// if the url field is empty
// if(isset($_POST['url']) && $_POST['url'] == ''){
// then send the form to your email
// mail( 'myemail#me.com', 'Contact Form', print_r($_POST,true) );
// }
// otherwise, let the spammer think that they got their message through
Use this code
if(isset($_POST['url']) && $_POST['url'] == '') {
if ($_POST['email'] != 'dukang2004#yahoo.com') {
// then send the form to your email
mail( 'myemail#me.com', 'Contact Form', print_r($_POST,true) );
}
}
Related
get error whe subscription Newsletter. How can fix?
Here is the problem and the solution to this bug:
When we enter an new email address (one that is not connected to an extisting subscriber), the subscriber object ($this) has no id ($this->getId(); // null) yet in Magento\Newsletter\Model\Subscriber::subscribe.
The verification email is sent out before the subscriber is saved, thus the subscriber id is missing from the verification link. The link does not do anything when you click on it because the verification method in Magento\Newsletter\Controller\Subscriber\Confirm::execute rejects the link because of the missing id.
You can easily mend the problem by calling $this->save() before calling $this->sendConfirmationRequestEmail();
try {
$this->save();
if($isConfirmNeed === true && $isOwnSubscribes === false)
{
$this->sendConfirmationRequestEmail();
} else {
$this->sendConfirmationSuccessEmail();
}
return $this->getStatus();
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
I simply moved the ''save'''- call a few lines up. sendConfirmationRequestEmail and sendConfirmationSuccessEmail do not seem to alter the $thisobject, so this is a valid change that does not break anything else.
I just changed the "Disable Email Communications" to yes in Magento 2 ( Stores > Configuration > Advanced > System > Mail Sending Settings > Disable Email Communications).
I'm trying to work with two forms in a single controller in Symfony2. The page is displaying a list of e-mail addresses with checkboxes to select them.
The first form is a research form and the second is used to remove e-mail addresses. There is also a pagination in my page.
My problem is that I can't remove an e-mail address with a research when the e-mail address is not displayed in the first page.
public function emailsAction(Request $request, $paginationParams)
{
$searchForm = $this->createForm(new SearchFormType(), null, array());
$searchForm->handleRequest($request);
if ($searchForm->isValid()) {
// FETCH E-MAILS WITH SEARCH
} else{
// FETCH E-MAILS WITHOUT SEARCH
}
// here I slice the result depending on the pagination params
$removeForm = $this->createForm(new RemoveFormType(), null, array(
'emails' => $emails
));
$removeForm->handleRequest($request);
if ($removeForm->isValid())
{
$formData = $removeForm->getData();
// here I remove the e-mails
}
...
$params['remove_form'] = $manageSubscribersForm->createView();
$params['search_form'] = $searchAbonneActuForm->createView();
return $this->renderView('my_template.html.twig', $params);
}
If I understand it correctly, the problem is that my removeForm is created with the spliced array and without the search applied when handling the removeForm.
When I search for a name, say johnsmith, it displays me on page 1, one result which is johnsmith#email.com.
If johnsmith#email.com is on page 2 without search, the removeForm handling my request is created with a spliced array not containing johnsmith, so the removeForm is not considered valid.
How should I do to create my removeForm, taking account of the search done before when submitting the removeForm? Or maybe I'm doing this wrong ?
I'm not a native english speaker so if anything is not clear, feel free to ask.
You can use a hidden field with the current page index, that will help you make your search again.
Or you can use an event listener to modify the form field before the submission for the validation.
this is a wordpress related question. I was wondering while using the ninja forms plugin, if it is possible to restrict the submission process to only allow #example.com email address to successfully submit the form.
Any ideas? I appreciate the time and responses from you all.
Please post the code for your form (even the generated html) so that the question stands the test of time!
You can do something like this in jQuery:
$('#signup').submit(function() {
validateEmail($('input').val());
return false;
});
function validateEmail(email) {
var re = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\#[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
if (re.test(email)) {
if (email.indexOf('#c-e.com', email.length - '#c-e.com'.length) !== -1) {
alert('Submission was successful.');
} else {
alert('Email must be a CE e-mail address (your.name#c-e.com).');
}
} else {
alert('Not a valid e-mail address.');
}
}
I found it in this working fiddle by Erik Woods:
http://jsfiddle.net/AkuXC/86/
This question is related to this Check email template after meta tag replacement and before sending in Mandrill.
I would like to know if there is a way to configure the Mandrill to send an email only when all the merge tags in the email template have been replaced. Is this possible?
AFAIK this isn't possible to configure with Mandrill.
You can (maybe should) perform this using the API however - take advantage of the render method to pre-render the outgoing email, and then look for any un-replaced fields.
function has_merge_tags($string)
{
return ( strpos("|*", $string) === false AND strpos("*|", $string) === false);
}
function send_email($template_code, $merge_fields)
{
$mandrill = new Mandrill(APIKEY);
// pre-render the template with the merged fields
$result = $mandrill->templates->render($name, array(), $merge_fields);
if (has_merge_tags($result['html']))
{
// throw exception, log it, whatever
}
really_send_email($result['html']);
}
https://mandrillapp.com/api/docs/templates.php.html#method=render
I'm new to working with Codeigniter and need to set a form validation rule and custom validation message for checking if the email address exists in the database that is submitted in a forgot password form. If the email address exists it sends an email, if it doesn't it should reload the form, set the field value to what the user entered and provide an error that the email address doesn't exist.
I've got the following in the controller...
public function forgot_password()
{
$this->form_validation->set_rules('email_address','Email Address','trim|required|valid_email');
if($this->form_validation->run() == FALSE)
{
$this->forgot_password_form();
}
else
{
$this->load->model('membership_model');
if($query = $this->membership_model->val_forgot_password())
{
$data['main_content'] = 'forgot_password_sent';
$this->load->view('includes/template', $data);
}
else
{
$this->form_validation->set_message('email_address','The email address you provided does not exist.');
$this->forgot_password_form();
}
}
}
and in the model...
public function val_forgot_password()
{
$this->db->where('email_address', $this->input->post('email_address'));
$query = $this->db->get($this->members);
if($query->num_rows == 1)
{
return true;
}
else
{
return false;
}
}
and the form is...
<?php
echo form_open('login/forgot_password');
echo "Email Address: " . form_input('email_address', set_value('email_address', ''));
echo br(2);
echo form_submit('submit','Send Email');
echo form_close();
echo br(1);
echo validation_errors('<p>Error: ');
?>
When the form is submitted with a valid email address it correctly goes to the success page but if the email address doesn't exist, it appears to reload the form but does not give an error.
Help pls! :D
You should use a callback to check the email exists. So your controller would be something like...
public function forgot_password()
{
$this->form_validation->set_rules('email_address','Email Address','trim|required|valid_email|callback__check_email_exists');
if($this->form_validation->run() == FALSE)
{
// VALIDATION ERRORS, SHOW VIEWS
}
else
{
// ALL IS GOOD, UPDATE EMAIL, AND REDIRECT TO CURRENT URL
}
}
And your callback (still in your controller) would be something like...
public function _check_email_exists($email)
{
// LOAD AND USE YOUR MODEL TO CHECK EMAIL EXISTS HERE
if ( ! $email_exists )
{
$this->form_validation->set_message('email_address', 'That email address don\'t exist, sucka!');
return FALSE;
}
else
{
return TRUE;
}
}
All this is spelled out in the excellent CI docs here, and I would recommend sticking to the CI conventions if you are new to it.
http://codeigniter.com/user_guide/libraries/form_validation.html
EDIT: There is also another problem i was facing while doing this in codeigniter3. You have to named the message field name to the callback. So instead of $this->form_validation->set_message('email_address', 'That email address don\'t exist, sucka!');
This should be
$this->form_validation->set_message('_check_email_exists', 'That email address don\'t exist, sucka!');
You should extend MY_Form_validation, this way your function can be used on any form, not just those that reside in your controller.