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));
}
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
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.
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… 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.
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.
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.
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.
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