Get the solution ↓↓↓
What it sounds like you want to do is first update the mail body with a string replacement, rather than using some hidden variable. With that, you can do something like this in your contact form mail tab. Where{{api_response}} will be replaced by whatever you define in the functionKiri_cf7_api_sender
/** Contact Form 7 Mail Tab in Editor **/
Dear [your-name],
This is the email body...
{{api_response}}
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
So now for the functionKiri_cf7_api_sender
add_action( 'wpcf7_before_send_mail', 'Kiri_cf7_api_sender' );
function Kiri_cf7_api_sender( $contact_form ) {
if ( 'Quote_form' === $contact_form->title ) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
$name = $posted_data['your-name'];
$surname = $posted_data['your-name2'];
$phone = $posted_data['tel-922'];
$urltest = $posted_data['dynamichidden-739']; // Not sure if this should be a form field, or just some kind of option field.
if ( strpos( $urltest, '?phone' ) !== false ) {
$url = 'api string';
} elseif ( strpos( $urltest, '?email' ) !== false ) {
$url = 'api string';
} else {
$url = 'api string';
$response = wp_remote_post( $url );
$body = wp_remote_retrieve_body( $response );
}
}
// Get the email tab from the contact form.
$mail = $contact_form->prop( 'mail' );
// Retreive the mail body, and string replace our placeholder with the field from the API Response.
// Whatever the api response is within the $body - if you have to json decode or whatever to get it.
$mail['body'] = str_replace( '{{api_response}}', $body['field'] , $mail['body'] );
// Update the email with the replaced text, before sending.
$contact_form->set_properties( array( 'mail' => $mail ) );
// Push a response to the event listener wpcf7mailsent.
$submission->add_result_props( array( 'my_api_response' => $body ) );
}
}
This should at least send the email, and allow you to add the API response to your email.
It also pushes an response to the javascript eventwpcf7mailsent which can be found by.
<script type="text/javascript">
document.addEventListener('wpcf7mailsent', function (event) {
console.log(event.detail.my_api_response);
}, false);
</script>
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
JavaScript is a multi-paradigm language that supports event-driven, functional, and mandatory (including object-oriented and prototype-based) programming types. Originally JavaScript was only used on the client side. JavaScript is now still used as a server-side programming language. To summarize, we can say that JavaScript is the language of the Internet.
https://www.javascript.com/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.