Some php error

Question Related To Php

Whenever I uses “URGENT” OR “important” on smtp mail setting my site shows 501 error SITE doesnt work with both tags i want to send an Mail with high importance tag so thats whenever used. but… this error appears always

$mail->addAddress($_POST['email'], $_POST['name']);
$mail->addReplyTo(CONTACTFORM_TO_ADDRESS, CONTACTFORM_TO_NAME);
$mail->Subject = "URGENT", "Submission Confirmation" . $_POST['Dopenews.in'];
$mail->Body = <<<EOT

I am suspecting this line:

Not sure why you are using a comma, think you mean to use concatenation?

$mail->Subject = "URGENT" . "Submission Confirmation" . $_POST['Dopenews.in'];

Or alternatively:

$mail->Subject = "URGENT: Submission Confirmation" . $_POST['Dopenews.in'];
7 Likes

I have already tried after removing i was also Thought that time but it isnt working the Problem is only with URGENT AND IMPORTANT after the subject, I Just that I just want to Send Mail WITH “Important Tag” with High Priority i set on mail it was 1 Since 1 Is the Highest Priority level To Send an Email but still Whenever someones Recieves It doesnt comes with Important tag -_-

Hey there, I reviewed your code and and seems there is a typo in your code.

$mail->Subject = “URGENT”, “Submission Confirmation” . $_POST[‘Dopenews.in’];

Above code you are using a coma instead of a dot after “URGENT”

this is the corrected code.

$mail->Subject = "URGENT Submission Confirmation " . $_POST[‘Dopenews.in’];

But The Mail Will come With Urgent Word Then If I dont Uses The comma after that

You want to exclude Urgent word?

I just want to when the Email arrive to person they will Recieve as an Important email ( With Important symbol )

Oh okay, I only have two solutions for you at the moment.

First you should add something like this

$mail->Subject = "IMPORTANT: Submission Confirmation " . $_POST[‘Dopenews.in’];

Second one will prioritize your email for the user, but keep in mind some mail clients are not supported this.

$mail->Priority = 1;
$mail->AddCustomHeader(“X-Priority: 1”);
$mail->AddCustomHeader(“X-MSMail-Priority: High”);
$mail->AddCustomHeader(“Importance: High”);

2 Likes

I am using phpmailer to send emails

Ok In the morning, I went to the office and find out that what has happened after changing the code. Because I don’t have a laptop or computer right now, I went to the office to check and updated it after using your code. Ok thanks anyways. YOU can read My Previous Messages Also Brother Priority 1 is highest Tho

1 Like

Did my code worked?

I AM USING GMAIL SMTP TO SEND AN EMAILS USING phpmailer
check your code please once again what u share.rectify if Please if its wrong

i have tried with your code

i knew it this would give an this error

With my experience, the code I provided should work as expected. Can you be more detailed about the issue you are facing?

Can you please provide me the source code?

check it

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->AddCustomHeader(“X-Priority: 1”);
    $mail->AddCustomHeader(“X-MSMail-Priority: High”);
    $mail->AddCustomHeader(“Importance: High”);
    $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.in] Submission Confirmation" . $_POST[('dopenews.in')];
$mail->Body = <<<EOT
Customer Name: {$_POST['name']}
Customer Email: {$_POST['email']}
Customer Message:
{$_POST['message']}
EOT;
try {
    $mail->send();
} catch (Exception $ex) {
    error_log("PHPMailer Exception: " . print_r($ex->errorMessage(), true));
    redirectWithError("An error occurred while trying to send your message.");
}

// SEND EMAIL FOR VISITOR
$mail = newMail();
$mail->addAddress($_POST['email'], $_POST['name']);
$mail->addReplyTo(CONTACTFORM_TO_ADDRESS, CONTACTFORM_TO_NAME);
$mail->Subject =IMPORTANT:"Submission Confirmation" . $_POST['dopenews.in'];
$mail->Body = <<<EOT
Dear {$_POST['name']},

Thanks for messaging us. We have received your email, and we'll respond to you within 24-48 hours. For the fastest response, you can use Instagram to contact us.

Regards, 
Dopenews Developer Team
www.dopenews.in
EOT;
try {
    $mail->send();
} catch (Exception $ex) {
    error_log("PHPMailer Exception: " . print_r($ex->errorMessage(), true));
    redirectWithError("An error occurred while trying to send your message.");
}

redirectSuccess();

I found what’s causing the issue.

You should remove the quotes around dope news. below code is the correct one.

$mail->Subject = "[Dopenews.in] Submission Confirmation " . $_POST[‘dopenews.in’];

same for the second one

$mail->Subject = "IMPORTANT: Submission Confirmation " . $_POST[‘dopenews.in’];

u mean ?
$mail->Subject = "[Dopenews.in] Submission Confirmation " . $_POST[dopenews.in];

$mail->Subject = "IMPORTANT: Submission Confirmation " . $_POST[dopenews.in];

now?? still same Error page isnt working.

Was it the full code? could you please provide me the link too?

dopenews.in/submit

i will turn on the display error give few minutes

okay

this is my full code now of this page and the errors u can check i have turned it on also dopenews.in/submit




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.

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->AddCustomHeader(“X-Priority: 1”);
    $mail->AddCustomHeader(“X-MSMail-Priority: High”);
    $mail->AddCustomHeader(“Importance: High”);
    $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.in] Submission Confirmation" . $_POST[dopenews.in];
$mail->Body = <<<EOT
Customer Name: {$_POST['name']}
Customer Email: {$_POST['email']}
Customer Message:
{$_POST['message']}
EOT;
try {
    $mail->send();
} catch (Exception $ex) {
    error_log("PHPMailer Exception: " . print_r($ex->errorMessage(), true));
    redirectWithError("An error occurred while trying to send your message.");
}

// SEND EMAIL FOR VISITOR
$mail = newMail();
$mail->addAddress($_POST['email'], $_POST['name']);
$mail->addReplyTo(CONTACTFORM_TO_ADDRESS, CONTACTFORM_TO_NAME);
$mail->Subject =IMPORTANT:"Submission Confirmation" . $_POST[dopenews.in];
$mail->Body = <<<EOT
Dear {$_POST['name']},

Thanks for messaging us. We have received your email, and we'll respond to you within 24-48 hours. For the fastest response, you can use Instagram to contact us.

Regards, 
Dopenews Developer Team
www.dopenews.in
EOT;
try {
    $mail->send();
} catch (Exception $ex) {
    error_log("PHPMailer Exception: " . print_r($ex->errorMessage(), true));
    redirectWithError("An error occurred while trying to send your message.");
}

redirectSuccess();```