I had a working simple Contact Form that would collect basic user information and send it to my recipient email address. I am still able to submit the form with a bogus email address (eg bob@fizz.pizz), but now I am unable to submit the form using a real email address (eg bob@gmail.com bob@aol.com bob@yahoo.com etc.).
Static application hosted at GoDaddy
I'm trying to determine if you can modify (by one character) the string a user passes to the email input field in the form to fake out the php validation FILTER_VALIDATE_EMAIL and allow the form to submit. Then, I'd replace the fake character (eg h gmail.com --> gmail.com) with an empty string '' , so the recipient would see the actual email submitted by the user.
contact.php
<?php
$receiving_email_address = 'my-gmail account';
if( file_exists($php_email_form = '../lib/php-email-form/php-email-form.php' )) {
include( $php_email_form );
} else {
die( 'Unable to load the "PHP Email Form" Library!');
}
$contact = new PHP_Email_Form;
$contact->ajax = true;
$contact->to = $receiving_email_address;
$contact->from_name = $_POST['name'];
$contact->from_email = $_POST['email'];
$contact->subject = $_POST['subject'];
$contact->add_message( $_POST['name'], 'From');
$contact->add_message( $_POST['email'], 'Email');
$contact->add_message( $_POST['message'], 'Message', 10);
echo $contact->send();
php-email-form.php
122 $to = filter_var( $this->to, FILTER_VALIDATE_EMAIL);
123 $from_name = filter_var( $this->from_name, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
124 $from_email = filter_var( $this->from_email, FILTER_VALIDATE_EMAIL);
125 $subject = filter_var( $this->subject, FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES);
126 $message = nl2br($this->message);
134 if( ! $from_email )
135 $this->error .= $this->error_msg['invalid_from_email'] . '<br>';
188 // Recipients
189 $mail->setFrom( $this->mailer, $from_name );
190 $mail->addAddress( $to );
191 $mail->addReplyTo( $from_email, $from_name );
635 public $SMTPDebug = 2;
index.html
<form action="forms/contact.php" method="post" role="form" class="php-email-form">
<div class="row">
<div class="col-md-6 form-group">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" required>
</div>
<div class="col-md-6 form-group mt-3 mt-md-0">
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email" required>
</div>
</div>
<div class="form-group mt-3">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" required>
</div>
<div class="form-group mt-3">
<textarea class="form-control" name="message" rows="5" placeholder="Message" required></textarea>
</div>
<div class="my-3">
<div class="loading">Loading</div>
<div class="error-message"></div>
<div class="sent-message">Your message has been sent. Thank you!</div>
</div>
<div class="text-center"><button type="submit">Send Message</button></div>
</form>
Error: Sending with mail()
Sendmail path: /usr/sbin/sendmail -t -i
Envelope sender: forms@my-domain.com
To: my-personal@gmail.com
Subject: Testing contact form
Headers: Date: Thu, 29 Sep 2022 14:29:56 +0000
From: Blah Blah <forms@my-domain.com>
Reply-To: Blah Blah <blah@gmail.com>
Message-ID: <bHXtvDgi6ajX6LSf6q9VojN6QQfMjHMILSTjOr04g@my-domain.com>
X-Mailer: PHP Email Form
MIME-Version: 1.0
Content-Type: text/html;
charset=utf-8
Additional params: -fforms@my-domain.com
Result: false
Could not instantiate mail function.
Mailer Error: Could not instantiate mail function.
After a few days of programming woes I found an easy fix, if not a best practice. By commenting out the following line at php-email-form.php my form submits successfully.
191 $mail->addReplyTo( $from_email, $from_name );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.