Skip to content

Commit

Permalink
curl cloud function
Browse files Browse the repository at this point in the history
  • Loading branch information
RedPi committed Mar 27, 2019
1 parent ed417cd commit 8dbdd16
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]';
// foreach ( $attachements as $attachement )
// {
// if ( file_exists( $attachement ) )
// {
// $attachments[] = $attachement;
// }
// }

$data = array(
'to' => '[email protected]',
'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.");
Expand Down

0 comments on commit 8dbdd16

Please sign in to comment.