gr1ns
Forum Replies Created
-
Hi @hoang,
I hope this message finds you well.
I wanted to follow up on my previous email regarding the JSON parsing issue I encountered while implementing the revised code snippet you provided. As a reminder, the error I’m facing is:
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 5 of the JSON data
Could you please update me on any progress or suggestions for troubleshooting this issue? Your assistance in resolving this matter would be greatly appreciated.
Thank you in advance for your support. I look forward to hearing from you soon.
Hi @hoang,
Thank you for your updated response and the revised code snippet. Unfortunately, after implementing the provided code, I still encounter an issue. Specifically, I receive the following error:
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 5 of the JSON data
This error suggests there might be an issue with the data being processed or returned within the email configuration or a related process. It’s unclear to me if this is directly tied to the
phpmailer_init
implementation or if there’s an issue elsewhere (e.g., in how the response or data is handled).Could you kindly assist in troubleshooting this error further? Are there additional steps I should take to validate the setup, or is there a way to ensure the returned data is correctly formatted?
Looking forward to your guidance.
Hi,
Thank you for your response and the provided code snippet.
I’ve tested the provided solution in my theme’s
functions.php
file, but I encountered an error related to the usage of$this
in the context of thephpmailer_init
action. Since the code snippet is a standalone function and not part of a class,$this
is unavailable, which results in the following error:Uncaught Error: Using $this when not in object context in /path-to-theme/functions.php:55
Stack trace:
#0 /wp-includes/class-wp-hook.php(324): {closure}()
#1 /wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
#2 /wp-includes/plugin.php(565): WP_Hook->do_action()
#3 /wp-includes/pluggable.php(540): do_action_ref_array()
#4 /wp-content/plugins/ninja-forms/includes/Actions/Email.php(108): wp_mail()This error occurs because
$this->providers_repository
cannot be used unless the function is part of a class.Can you confirm if the
providers_repository
should be passed as a global object or instantiated directly in the snippet? Alternatively, should the snippet be integrated into a class with the$this
context?Hi Hoang,
Thank you for the code snippet. However, I’m looking to dynamically set the “From” email address to match the email address that users enter in the form, rather than using a fixed address.
Specifically, I want each email sent to have the “From” address populated with the user’s email from the form submission, so the recipient can see it as the sender’s address. Could you provide guidance on how to implement this?
Thank you for your help and clarification.