I'm trying to implement a contact form on a website running PHP 8.1 with the latest PHPMailer()
code but it won't send any mails. I don't know how to debug it remotely since the webserver doesn't allow SSH
(I can debug it to some extent with xdebug on a localhost) and I got it to work with an older PHPMailer()
library and the webserver running on PHP 7.4. All the error logging is turned on on the webserver error_reporting
set to -1
and display_errors
to 1
and no errors are visible (not in the browser console, the error logs of the server or in the browser). SMTP
can't be used in this case so it must send with sendmail
. The site contact.php
includes
require_once("contact/include/fgcontactform.php");
This is in fgcontactform.php
require_once("PHPMailer.php");
require_once("Exception.php");
//require_once("SMTP.php");
/*
Interface to Captcha handler
*/
class FG_CaptchaHandler
{
function Validate() { return false;}
function GetError(){ return '';}
}
/*
FGContactForm is a general purpose contact form class
It supports Captcha, HTML Emails, sending emails
conditionally, File atachments and more.
*/
class FGContactForm
{
var $receipients;
var $errors;
var $error_message;
var $name;
var $email;
var $message;
var $from_address;
var $form_random_key;
var $conditional_field;
var $arr_conditional_receipients;
var $fileupload_fields;
var $captcha_handler;
var $mailer;
function __construct()
{
$this->receipients = array();
$this->errors = array();
$this->form_random_key = 'HTgsjhartag';
$this->conditional_field='';
$this->arr_conditional_receipients=array();
$this->fileupload_fields=array();
$this->mailer = new PHPMailer\PHPMailer\PHPMailer();
$this->mailer->CharSet = 'utf-8';
}
This is the form HTML in contact.php
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
This is the function in fgcontactform.php
function GetSelfScript()
{
return htmlentities($_SERVER['PHP_SELF']);
}
When I click on SEND MESSAGE
on the contact form it should redirect to some external website which works with the old PHPMailer()
but not with the new one in contact.php
{
if($formproc->ProcessForm())
{
$formproc->RedirectToURL("https://www.google.com/");
}
}
This is the POST request from the Firefox Dev console
-----------------------------12990316242892709467429570469
Content-Disposition: form-data; name="submitted"
1
-----------------------------12990316242892709467429570469
Content-Disposition: form-data; name="id8d10e0a2c32d37a59eed"
b433f008dc4d6209e071b3b3a2b8459a
-----------------------------12990316242892709467429570469
Content-Disposition: form-data; name="spc1b79d21e61baf3fd8e15f01ff9b5c80"
-----------------------------12990316242892709467429570469
Content-Disposition: form-data; name="name"
test
-----------------------------12990316242892709467429570469
Content-Disposition: form-data; name="email"
test@test.com
-----------------------------12990316242892709467429570469
Content-Disposition: form-data; name="message"
test
-----------------------------12990316242892709467429570469
Content-Disposition: form-data; name="upload1"; filename=""
Content-Type: application/octet-stream
-----------------------------12990316242892709467429570469
Content-Disposition: form-data; name="upload2"; filename=""
Content-Type: application/octet-stream
-----------------------------12990316242892709467429570469
Content-Disposition: form-data; name="scaptcha"
VAGEHL
-----------------------------12990316242892709467429570469--
Update 1: This should send the message
function SendFormSubmission()
{
$this->CollectConditionalReceipients();
$this->mailer->CharSet = 'utf-8';
$this->mailer->Subject = "Kontaktaufnahme von $this->name";
$this->mailer->From = $this->GetFromAddress();
$this->mailer->FromName = $this->name;
$this->mailer->AddReplyTo($this->email);
$message = $this->ComposeFormtoEmail();
$textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
$this->mailer->AltBody = @html_entity_decode($textMsg,ENT_QUOTES,"UTF-8");
$this->mailer->MsgHTML($message);
$this->AttachFiles();
if(!$this->mailer->Send())
{
$this->add_error("Fehler beim Senden der Nachricht!");
return false;
}
return true;
}
I've also swapped var
with public
The reply is contact.php
although that should redirect me to google.com
.
Can anyone help me debug this problem or give hints as to what I'm doing wrong here?