Some Php Configuration

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!

Now check again different error now

Hi dopebrest,

Instead of asking every time you make a minor change, please try to check your code thoroughly for the structure and spelling before asking with the error message displayed, otherwise you cannot learn from the process and it will take a long time getting to resolve your issue.

Cheers!

5 Likes

I have check now already there was Exception spelling error before which i hve correct thm but hvnt found any error but as per the system am gettin error

I just copied paste that but the same error. which i shown on before

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

…honestly really pissed off today

Hi dopebrest,

I can’t tell if the catch is immediately after try{} from the information provided, please try again and we’ll check tomorrow.

Cheers!

3 Likes

… yea ok we will Try on tomorrow morning thanks for your cooperation and time.

hey are u free now ? we need admin support for that since our issue is not getting fix one error fix another error comes on our head -_- some stack member said me to add Missing { brackets on it but now i m not ablle to find other issue

Parse error : syntax error, unexpected token “<<”
this error is because the subject is missing from their maybe

Hi dopebrest,

Please show your formatted code regarding the error.

Cheers!

1 Like

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


    try {
        
    $mail = 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();


try {     
    $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 Exception: ".print_r($ex->errorMessage(),true));  } ````

Hi dopebrest,

From what you have pasted, the issue for code structure is still not solved.

Please review the first bit of the try block, and you’ll notice there isn’t a catch statement immediately after the }. Meanwhile, the entire try block is meaningless here as you have overwritten the $mail variable after. The first try block can be removed entirely as the settings are already defined from within the newMail() function.

To take advantage of the try catch feature, wrap it for each email you intend to send and catch exceptions whenever necessary.

The middle 2 parts of the email send are completely fine on their own, however, somehow there’s a 2nd try block at the bottom that is not associated with the 2 emails you intend to do.

I suggest you remove all try blocks including it’s content so that you have 2 blocks of plain code creating the 2 emails, then attempt to apply try block again. This way you can get a clearer view of your code. Your current version not easy to view and understand if you’re not familiar with try catch. Therefore cleaning things up first before making changes would make things easier for you.

You should be left with this code after cleaning up:

// 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();

Cheers!

3 Likes

i understand little things but Can You just Provide The code By editing or how it should be… because i dont want to see another error again… So please Kindly u that for me just. so we have to to put two Catch Exception for that ? to gettin dis work

Hi dopebrest,

Web system development is my profession and I make a living on it, as do all programmers in the world. While I can definitely do the whole thing, I don’t find doing this for free appropriate and fair to other developers as well. Either you have a very strong reason, or you have to learn to code or pay to hire professional service through proper channels.

My rationale here is to offer help, connect with enthusiasts and connect with people who share the same interests, we share our knowledge and learn in the process while helping those who need technical support specifically for using this free hosting.

Cheers!

6 Likes

well i respect your words i m using this infinityfree since 3-4 years i also helped so many Peoples Before You can check my posts also i am not guy who only looking for free help am not working anywhere but still trying my best to livei got epilepsy attack the day before yesterday only i am and my parents now the truth about this what is happening with my world now a day my brain isnt working how it should be inow a days brain also its not in my hand brother! some things i dont remembered i knows even C++ i was developer in SMF Forums before 3 years but rip to my brain now …even my english level goin down day by day i dont know when ever i dies in this 27 age only sorry for that but i cant control to my self this place is not for that but… this is only the reason am getting an issues while understanding this…thats why i said u to right code for this fix otherwise i could do… thanks for your still u are saying for my personal benifits tho. but i need that to get is fixed and work properly i have tried my best to get it fix… maybe you guys will do that…

If you are really going through epilepsy then take a break, the code is less important than your health. (Be sure to avoid anything that may trigger it as well)

This does not excuse asking for free help however, people have their own life or health problems. Someone who is generous enough and has a lot of free time may do it but even then you are only the one who can help himself (again refer to the first paragraph)

5 Likes

i know that i m not asking for free help i made all that code my self tho i whole site i was just stuck on some php issues iin contact page only…

There is no point in denying. It is ok to take break when you arent ready to handle something.

7 Likes