From 8dbdd16d1419634302573e97e1f0a97e5e8c8fb1 Mon Sep 17 00:00:00 2001 From: Red Pi Date: Wed, 27 Mar 2019 12:48:21 +0100 Subject: [PATCH] curl cloud function --- src/Helper/FormHelper.php | 42 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/src/Helper/FormHelper.php b/src/Helper/FormHelper.php index ee08bcf..6305a2e 100644 --- a/src/Helper/FormHelper.php +++ b/src/Helper/FormHelper.php @@ -72,17 +72,39 @@ public static function send($to='admin', $subject='New message from website', $f $body .= ($form[$key] ? ' - ' . $key . ' : ' . $form[$key] . "\n" : ''); } - foreach ( $attachements as $attachement ) - { - if ( file_exists( $attachement ) ) - { - $attachments[] = $attachement; - } - } - - $headers = 'From: plerouge@eleven-labs.com'; + // foreach ( $attachements as $attachement ) + // { + // if ( file_exists( $attachement ) ) + // { + // $attachments[] = $attachement; + // } + // } + + $data = array( + 'to' => 'plerouge@eleven-labs.com', + 'subject' => $subject, + 'content' => $body + ); + + $payload = json_encode($data); + + $ch = curl_init('https://us-central1-valtus.cloudfunctions.net/email'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLINFO_HEADER_OUT, true); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); + + // Set HTTP Header for POST request + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($payload)) + ); + + // Submit the POST request + $result = curl_exec($ch); + // if ( wp_mail( $to, $subject, $body, $attachments ) ) - if ( mail($to, $subject, $body, $headers)) + if (curl_exec($ch)) return $form; else return new \WP_Error('send_mail', "The server wasn't able to send the email.");