Some Php Configuration

As a practice, do not dump the whole code like that, you should format your code as this for readablity:
```
Test
```

4 Likes

not working i am facing now https error (ssl error or what didnt get that

Hi dopebrest,

HTTPS errors relates to your browser connectivity to the server being correctly encrypted or not, rather than the code. Please share a screenshot so we can see better and solve the issue together. :+1:

Cheers!

Hi Ziverre,

Maybe he/she tried, but there are some special characters in between that broke the formatting, which is understandable.

Cheers!

1 Like

i have already shown u my website and all my php mailer brother i can show u what i have done now before my email was working but after that auto responder i m facing that http error now. please check my Php mailer Correcly. i have already mentioned Function.php in my and config and .php also on my previous post You can also try by visiting my site dopenews.in/contact

<?php

require_once __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/functions.php';
require_once __DIR__.'/config.php';

session_start();

// Basic check to make sure the form was submitted.
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
    redirectWithError("The form must be submitted with POST data.");
}

// Do some validation, check to make sure the name, email and message are valid.
if (empty($_POST['g-recaptcha-response'])) {
    redirectWithError("Please complete the CAPTCHA.");
}

$recaptcha = new \ReCaptcha\ReCaptcha(CONTACTFORM_RECAPTCHA_SECRET_KEY);
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_REQUEST['REMOTE_ADDR']);

if (!$resp->isSuccess()) {
    $errors = $resp->getErrorCodes();
    $error = $errors[0];

    $recaptchaErrorMapping = [
        'missing-input-secret' => 'No reCAPTCHA secret key was submitted.',
        'invalid-input-secret' => 'The submitted reCAPTCHA secret key was invalid.',
        'missing-input-response' => 'No reCAPTCHA response was submitted.',
        'invalid-input-response' => 'The submitted reCAPTCHA response was invalid.',
        'bad-request' => 'An unknown error occurred while trying to validate your response.',
        'timeout-or-duplicate' => 'The request is no longer valid. Please try again.',
    ];

    $errorMessage = $recaptchaErrorMapping[$error];
    redirectWithError("Please retry the CAPTCHA: ".$errorMessage);
}

if (empty($_POST['name'])) {
    redirectWithError("Please enter your name in the form.");
}

if (empty($_POST['email'])) {
    redirectWithError("Please enter your email address in the form.");
}

if (empty($_POST['subject'])) {
    redirectWithError("Please enter your message in the form.");
}

if (empty($_POST['message'])) {
    redirectWithError("Please enter your message in the form.");
}

if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
    redirectWithError("Please enter a valid email address.");
}

if (strlen($_POST['message']) < 10) {
    redirectWithError("Please enter at least 10 characters in the message field.");
}

// Everything seems OK, time to send the email.

$mail = new \PHPMailer\PHPMailer\PHPMailer(true);

try newMail(){
    $mail = new \PHPMailer\PHPMailer\PHPMailer(true);
    $mail->SMTPDebug = CONTACTFORM_PHPMAILER_DEBUG_LEVEL;
    $mail->isSMTP();
    $mail->Host = CONTACTFORM_SMTP_HOSTNAME;
    $mail->SMTPAuth = true;
    $mail->Username = CONTACTFORM_SMTP_USERNAME;
    $mail->Password = CONTACTFORM_SMTP_PASSWORD;
    $mail->SMTPSecure = CONTACTFORM_SMTP_ENCRYPTION;
    $mail->Port = CONTACTFORM_SMTP_PORT;
    $mail->Priority = 1;
    $mail->setFrom(CONTACTFORM_FROM_ADDRESS, CONTACTFORM_FROM_NAME);
    return $mail;

}
    // SEND EMAIL FOR INTERNAL
$mail = newMail();
$mail->addAddress(CONTACTFORM_TO_ADDRESS, CONTACTFORM_TO_NAME);
$mail->Subject = "Dopenews-Contact us ".$_POST['Dopenews Support'];
$mail->Body    = <<<EOT
Name: {$_POST['name']}
Email: {$_POST['email']}
Message:
{$_POST['message']}
EOT;
$mail->send();

// SEND EMAIL FOR VISITOR
$mail = newMail();
$mail->addAddress($_POST['email'], $_POST['name']);
$mail->addReplyTo(CONTACTFORM_TO_ADDRESS, CONTACTFORM_TO_NAME);
$mail->Subject = "Dopenews-Contact us ".$_POST['Dopenews Support'];
$mail->Body    = <<<EOT
Name: {$_POST['name']}
Email: {$_POST['email']}
Message:
Thanks for contacting us we will Respond Shortly.
EOT;
$mail->send();

    $mail->Body    = <<<EOT

Name: {$_POST['name']}
Email: {$_POST['email']}
Message: 
{$_POST['message']}
EOT;

    $mail->send();
    redirectSuccess();
    
catch (Exception $ex) {
    redirectWithError("An error occurred while trying to send your message.");
    error_log("PHPMailer Exeption: ".print_r($ex->errorMessage(),true)); 
}

What is your website’s URL, and do you have an SSL certificate installed?

2 Likes

i have valid ssl for my site but still that issue u can see through my website -_- its fully protected i have mentioned my website you can check it through

Sorry, I missed the last part of your previous message.

I do not get an SSL error, but rather an HTTP ERROR 500. Can you activate the Display Errors setting and see what you get?

5 Likes

No Problem but…I have already Deleted my htacess file i have removed all permission.

I don’t suspect your .htaccess, I think the error may be in your PHP code. Can you do this?

6 Likes

Done i have enabled that

Thats an error

Parse error : syntax error, unexpected identifier “newMail”, expecting “{” in htdocs/submit.php on line 67

This line is incorrect:

try newMail(){

You shouldn’t have anything after the try statement, it should be:

try {
    /* your code here */
}
catch (Exception $ex) {
    /* your code here */
}

Your code seems to be structured wrong in any case, as you close your try statement, then try to call the function newMail() (which you have not declared, I’m guessing it is meant to be where the try statement is) and later on have a catch statement that does not do anything on its own.

Did you try to copy @chiucs123’s code? If so you might want to replace lines 67 up to the end with something like this:

function newMail(){
	$mail = new \PHPMailer\PHPMailer\PHPMailer(true);
	$mail->SMTPDebug = CONTACTFORM_PHPMAILER_DEBUG_LEVEL;
	$mail->isSMTP();
	$mail->Host = CONTACTFORM_SMTP_HOSTNAME;
	$mail->SMTPAuth = true;
	$mail->Username = CONTACTFORM_SMTP_USERNAME;
	$mail->Password = CONTACTFORM_SMTP_PASSWORD;
	$mail->SMTPSecure = CONTACTFORM_SMTP_ENCRYPTION;
	$mail->Port = CONTACTFORM_SMTP_PORT;
	$mail->Priority = 1;
	$mail->setFrom(CONTACTFORM_FROM_ADDRESS, CONTACTFORM_FROM_NAME);
	return $mail;
}

try {
	// SEND EMAIL FOR INTERNAL
	$mail = newMail();
	$mail->addAddress(CONTACTFORM_TO_ADDRESS, CONTACTFORM_TO_NAME);
	$mail->Subject = "Dopenews-Contact us ".$_POST['Dopenews Support'];
	$mail->Body    = <<<EOT
	Name: {$_POST['name']}
	Email: {$_POST['email']}
	Message:
	{$_POST['message']}
	EOT;
	$mail->send();
}
catch (Exception $ex) {
    redirectWithError("An error occurred while trying to send your message.");
    error_log("PHPMailer Exeption: ".print_r($ex->errorMessage(),true)); 
}

try {
	// SEND EMAIL FOR VISITOR
	$mail = newMail();
	$mail->addAddress($_POST['email'], $_POST['name']);
	$mail->addReplyTo(CONTACTFORM_TO_ADDRESS, CONTACTFORM_TO_NAME);
	$mail->Subject = "Dopenews-Contact us ".$_POST['Dopenews Support'];
	$mail->Body    = <<<EOT
	Name: {$_POST['name']}
	Email: {$_POST['email']}
	Message:
	Thanks for contacting us we will Respond Shortly.
	EOT;
	$mail->send();
	redirectSuccess();
}
catch (Exception $ex) {
    redirectWithError("An error occurred while trying to send your message.");
    error_log("PHPMailer Exeption: ".print_r($ex->errorMessage(),true)); 
}

I wrapped the internal and visitor emails in two separate try-catch statements, as I was unsure if it was right to have them merged in one. I think there might be something wrong with the way you use error_log as well (does redirectWithError not prevent it from executing?), but I’m unsure.

5 Likes

I am using an Cloudflare i didnt do anything with Error Logs You can Check my Php mailer Dude i have sent All My files to you With with Full Trust ‘:’) Actually u told to add Those lines For new mail thats why i have Tried So What Code should i use on their instead of that i am also New in this So dont know much instead Of Html thats why i am asking for that code help… sorry if you mind… :sweat_smile: i had Set my Functions setting i configured my Functions.php also doesnt seems any error from there

Cloudflare is unrelated to the current issue that you are facing, 500 indicates that there is a problem with the code when the display error isn’t enabled.

Getting started with something complex such as that as a starter is not like shooting a fish in the barrel, community members here provide you the help as if you are able to help yourself based on the provided answer or feedback. You need to make use of Google or the search engine of preference, learn basics such as how to debug etc.

I understand that this may not be the response that you were looking for nor an answer, but learning at least the basics will save you and others from headache.

5 Likes

Hi dopebrest,

My code was meant to demonstrate what you’re trying to achieve, I didn’t expect a full copy and paste from your end.

For try catch blocks, please refer to ChrisPAR for the correct syntax and apply the code to the appropriate positions, which he has already pointed for you.

For me, I’m not simply taking a stack of code and have the solution done for you. You have to learn and code it yourself. It was never about trust issues.

Cheers!

4 Likes

Thanks for everything bro but now that facing that error now after that…



Hi dopebrest,

You’re not doing try catch syntax correctly, please reference ChrisPAR’s guide, you have to place try{} catch{} correctly.

Meanwhile, if you have a laptop, try coding there instead of using mobile phone as you’ll have limited horizontal visibility to the code, making it hard for proper indentation and view on code blocks. Alternatively, use the app horizontally.

Cheers!

3 Likes

Read my Files Correctly bru i have did that same getting error while on Catch idk why… dopenews.in/submit.php

Hi dopebrest,

I’m quite sure that I’m reading this correctly and you did not place a catch block right after the try{} block.

You might want to check this part and try again on line 83.

image

Cheers!