an-and-simple-contact-form-by-meg-nicholas' ); } //email invalid address if ( strlen( $this->Email ) > 0 && ! filter_var( $this->Email, FILTER_VALIDATE_EMAIL ) ) { $this->Errors['email'] = esc_html__( 'Please enter a valid email address.', 'clean-and-simple-contact-form-by-meg-nicholas' ); } //mandatory phone number if ( cscf_PluginSettings::PhoneNumber() && cscf_PluginSettings::PhoneNumberMandatory() ) { if ( strlen( $this->PhoneNumber ) < 8 ) { $this->Errors['confirm-email'] = esc_html__( 'Please enter a valid phone number.', 'clean-and-simple-contact-form-by-meg-nicholas' ); } } //contact consent if ( cscf_PluginSettings::ContactConsent() ) { if ( ! $this->ContactConsent ) { $this->Errors['contact-consent'] = esc_html__( 'Please give your consent.', 'clean-and-simple-contact-form-by-meg-nicholas' ); } } //check recaptcha but only if we have keys if ( $this->RecaptchaPublicKey <> '' && $this->RecaptchaPrivateKey <> '' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- No action, no form fields are being saved $resp = csf_RecaptchaV2::VerifyResponse( sanitize_text_field($_SERVER["REMOTE_ADDR"]??''), $this->RecaptchaPrivateKey, sanitize_text_field($_POST["g-recaptcha-response"]??'')); if ( ! $resp->success ) { $this->Errors['recaptcha'] = esc_html__( 'Please solve the recaptcha to continue.', 'clean-and-simple-contact-form-by-meg-nicholas' ); } } return count( $this->Errors ) == 0; } public function SendMail() { apply_filters( 'cscf_spamfilter', $this ); if ( $this->IsSpam === true || $this->IsSpam === 'BOT' || $this->IsSpam === 'DENY' ) { return true; } $filters = new cscf_Filters; if ( cscf_PluginSettings::OverrideFrom() & cscf_PluginSettings::FromEmail() != "" ) { $filters->from_email = cscf_PluginSettings::FromEmail(); } else { $filters->from_email = $this->Email; } $filters->from_name = $this->Name; //add filters $filters->add( 'wp_mail_from' ); $filters->add( 'wp_mail_from_name' ); //headers $header = "Content-Type: text/plain\r\n" . "Reply-To: " . $this->Name . " <" . $this->Email . ">\r\n" . "X-Entity-Ref-ID: " . uniqid() . "\r\nX-Form-CFCS\r\n"; //message $message = esc_html__( 'From', 'clean-and-simple-contact-form-by-meg-nicholas' ) . ': ' . esc_attr( $this->Name ) . "\n\n"; $message .= esc_html__( 'Email', 'clean-and-simple-contact-form-by-meg-nicholas' ) . ': ' . esc_attr( $this->Email ) . "\n\n"; if ( cscf_PluginSettings::PhoneNumber() ) { $message .= esc_html__( 'Phone', 'clean-and-simple-contact-form-by-meg-nicholas' ) . ': ' . esc_attr( $this->PhoneNumber ) . "\n\n"; } $message .= esc_html__( 'Page URL', 'clean-and-simple-contact-form-by-meg-nicholas' ) . ': ' . get_permalink( $this->PostID ) . "\n\n"; $message .= esc_html__( 'Message', 'clean-and-simple-contact-form-by-meg-nicholas' ) . ':' . "\n\n" . esc_html( $this->Message ) . "\n\n"; if ( cscf_PluginSettings::ContactConsent() ) { $message .= cscf_PluginSettings::ContactConsentMsg() . ': ' . ( $this->ContactConsent ? esc_html__( 'yes', 'clean-and-simple-contact-form-by-meg-nicholas' ) : esc_html__( 'no', 'clean-and-simple-contact-form-by-meg-nicholas' ) ); } $emails = apply_filters( 'cscf_email_emails', cscf_PluginSettings::RecipientEmails() ); $subject = apply_filters( 'cscf_email_subject', cscf_PluginSettings::Subject() ); $message = apply_filters( 'cscf_email_message', stripslashes( $message ) ); $header = apply_filters( 'cscf_email_header', $header ); $result = wp_mail( $emails, $subject, $message, $header ); //remove filters (play nice) $filters->remove( 'wp_mail_from' ); $filters->remove( 'wp_mail_from_name' ); //send an email to the form-filler if ( $this->EmailToSender ) { $recipients = cscf_PluginSettings::RecipientEmails(); if ( cscf_PluginSettings::OverrideFrom() & cscf_PluginSettings::FromEmail() != "" ) { $filters->from_email = cscf_PluginSettings::FromEmail(); } else { $filters->from_email = $recipients[0]; } $filters->from_name = get_bloginfo( 'name' ); //add filters $filters->add( 'wp_mail_from' ); $filters->add( 'wp_mail_from_name' ); $header = "Content-Type: text/plain\r\n"; $message = cscf_PluginSettings::SentMessageBody() . "\n\n"; $message .= esc_html__( 'Here is a copy of your message :', 'clean-and-simple-contact-form-by-meg-nicholas' ) . "\n\n"; if ( cscf_PluginSettings::ContactConsent() ) { $message .= cscf_PluginSettings::ContactConsentMsg() . ': ' . ( $this->ContactConsent ? esc_html__( 'yes', 'clean-and-simple-contact-form-by-meg-nicholas' ) : esc_html__( 'no', 'clean-and-simple-contact-form-by-meg-nicholas' ) ) . "\n\n"; } if ( cscf_PluginSettings::PhoneNumber() ) { $message .= esc_html__( 'Phone', 'clean-and-simple-contact-form-by-meg-nicholas' ) . ': ' . esc_attr( $this->PhoneNumber ) . "\n\n"; } $message .= esc_html__( 'Message', 'clean-and-simple-contact-form-by-meg-nicholas' ) . ':' . "\n\n" . esc_html( $this->Message ) . "\n\n"; $result = ( wp_mail( $this->Email, cscf_PluginSettings::Subject(), stripslashes( $message ), $header ) ); //remove filters (play nice) $filters->remove( 'wp_mail_from' ); $filters->remove( 'wp_mail_from_name' ); } return $result; } }