forked from metabolism/wordpress-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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."); | ||
|