public function send() { $data = json_decode($this->app->request->getBody(), true); $name = $data['name']; $email = $data['email']; $phone = $data['phone']; $event = $data['event']; $date = $data['date']; $timeFrom = $data['timeFrom']; $timeTo = $data['timeTo']; $place = $data['place']; $sound = $data['sound']; $light = $data['light']; $setup = $data['setup']; $renown = $data['renown']; $description = isset($data['description']) ? '' : $data['description']; $captcha = $data['captcha']; $valid = !empty($name); $valid = !$valid ? false : preg_match('/^[a-z]+[a-z0-9._]+@[a-z]+\\.[a-z.]{2,5}$/', $email); $valid = !$valid ? false : preg_match('/^[\\+0-9][0-9\\s]*/', $phone); $valid = !$valid ? false : !empty($event); $valid = !$valid ? false : !empty($date); $valid = !$valid ? false : !empty($timeFrom); $valid = !$valid ? false : !empty($timeTo); $valid = !$valid ? false : !empty($place); $valid = !$valid ? false : !empty($sound); $valid = !$valid ? false : !empty($light); $valid = !$valid ? false : !empty($setup); $valid = !$valid ? false : !empty($renown); //$valid = !$valid ? false : !empty($description); $valid = !$valid ? false : !empty($captcha); if ($valid) { $data['date'] = preg_replace('/\\//', '-', $date); $client = new \GuzzleHttp\Client(); $response = $client->get('https://www.google.com/recaptcha/api/siteverify', ['query' => ['response' => $captcha, 'secret' => getenv('RECAPTCHA_SERVERKEY')]]); if (empty($response)) { $valid = false; } else { $valid = json_decode($response->getBody())->success; } } if ($valid) { $mgClient = new \Mailgun\Mailgun(getenv('MAILGUN_APPKEY')); $domain = getenv('MAILGUN_DOMAIN'); // Message to customer $mgClient->sendMessage($domain, ['from' => getenv('BOOKING_FROM'), 'to' => "<{$data['email']}>", 'subject' => 'Bokningsförfrågan - Platoon DJs', 'text' => "Vi har mottagit din förfrågan för bokning av DJ. Vi kommer höra av oss så snart vi kan för att hitta en anpassad offert till just ditt event.\n\n(OBS: Det här meddelandet går inte att svara på, hör av dig till <*****@*****.**> istället om det är några oklarheter)\n\n\nMVH//\nPlatoon DJs"]); // Message to customer relations $data['captcha'] = true; $result = $mgClient->sendMessage($domain, ['from' => "{$data['name']} <{$data['email']}>", 'to' => getenv('BOOKING_TO'), 'subject' => "Bokningsförfrågan Platoon DJs: {$data['name']}, {$data['event']} i/på {$data['place']} {$data['date']}", 'html' => $this->getEmail('e-request.php', $data)]); echo json_encode(compact('valid')); } else { echo json_encode(compact('valid')); } }
protected function _send() { $this->type = 'html'; $message = $this->build_message(); $mg = new \Mailgun\Mailgun($this->config['mailgun']['key']); // Mailgun does not consider these "arbitrary headers" $exclude = array('From' => 'From', 'To' => 'To', 'Cc' => 'Cc', 'Bcc' => 'Bcc', 'Subject' => 'Subject', 'Content-Type' => 'Content-Type', 'Content-Transfer-Encoding' => 'Content-Transfer-Encoding'); $headers = array_diff_key($this->headers, $exclude); foreach ($this->extra_headers as $header => $value) { $headers[$header] = $value; } // Standard required fields $post_data = array('from' => $this->config['from']['email'], 'to' => static::format_addresses($this->to), 'subject' => $this->subject, 'html' => $message['body']); // Optionally cc, bcc and alt_body $this->cc and $post_data['cc'] = static::format_addresses($this->cc); $this->bcc and $post_data['bcc'] = static::format_addresses($this->bcc); $this->alt_body and $post_data['text'] = $this->alt_body; // Mailgun's "arbitrary headers" are h: prefixed foreach ($headers as $name => $value) { $post_data["h:{$name}"] = $value; } // Add the attachments $post_body = array('attachment' => array(), 'inline' => array()); foreach ($this->attachments['attachment'] as $cid => $file) { $post_body['attachment'][] = array('filePath' => $file['file'][0], 'remoteName' => $file['file'][1]); } foreach ($this->attachments['inline'] as $cid => $file) { $post_body['inline'][] = array('filePath' => $file['file'][0], 'remoteName' => substr($cid, 4)); } // And send the message out $mg->sendMessage($this->config['mailgun']['domain'], $post_data, $post_body); return true; }
function send($result, $template, $subject = 'sibip') { \app\log('sending prep'); $config = \configuration\load(); $mailgun = new \Mailgun\Mailgun($config['key']); $domain = $config['domain']; \app\log('composed'); $mailgun->sendMessage($domain, array('from' => '*****@*****.**', 'to' => \app\run('input', 'post', 'sender'), 'subject' => $subject, 'text' => \email\composeText($result), 'html' => \email\composeHTML($template, $result))); }
protected function _send() { $message = $this->build_message(); $mg = new \Mailgun\Mailgun($this->config['mailgun']['key']); // Mailgun does not consider these "arbitrary headers" $exclude = array('From' => 'From', 'To' => 'To', 'Cc' => 'Cc', 'Bcc' => 'Bcc', 'Subject' => 'Subject', 'Content-Type' => 'Content-Type', 'Content-Transfer-Encoding' => 'Content-Transfer-Encoding'); $headers = array_diff_key($this->headers, $exclude); foreach ($this->extra_headers as $header => $value) { $headers[$header] = $value; } // Standard required fields $post_data = array('from' => $this->config['from']['email'], 'to' => static::format_addresses($this->to), 'subject' => $this->subject, 'html' => $message['body']); // Optionally cc and bcc $this->cc and $post_data['cc'] = static::format_addresses($this->cc); $this->bcc and $post_data['bcc'] = static::format_addresses($this->bcc); // Mailgun's "arbitrary headers" are h: prefixed foreach ($headers as $name => $value) { $post_data["h:{$name}"] = $value; } $mg->sendMessage($this->config['mailgun']['domain'], $post_data); return true; }
/** * https://documentation.mailgun.com/api-sending.html#examples */ function send(array $params = [], &$error_message = '') { require_php_lib('mailgun'); $error_message = null; try { $mg = new Mailgun\Mailgun($this->key); $opts = $this->PARENT->ALLOW_ATTACHMENTS ? ['attachment' => array_values($params['attaches'])] : []; // Now, compose and send your message. $result = $mg->sendMessage($this->domain, ['from' => $params['email_from'], 'to' => $params['email_to'], 'subject' => $params['subject'], 'text' => $params['text'], 'html' => $params['html']], $opts); } catch (Exception $e) { $error_message = 'A mailgun error occurred: ' . get_class($e) . ' - ' . $e->getMessage(); } if (@$error_message && DEBUG_MODE && $this->PARENT->MAIL_DEBUG_ERROR) { trigger_error($error_message, E_USER_WARNING); } if (is_callable($params['on_after_send'])) { $callback = $params['on_after_send']; $callback($mail, $params, $result, $error_message, $this->PARENT); } $this->PARENT->_last_error_message = $error_message; return $result && !$error_message ? true : false; }
public static function send($to, $subject, $text) { $enabled = sfConfig::get('app_mailgun_enabled', false); $key = sfConfig::get('app_mailgun_key', null); $domain = sfConfig::get('app_mailgun_domain', null); $from = sfConfig::get('app_mailgun_from', null); if (!$enabled or !$key) { return false; } if ($to === '' or is_array($to) && count($to) < 1) { return false; } $mgClient = new Mailgun\Mailgun($key); if (is_array($to)) { $to = implode(',', $to); } $result = false; try { $result = $mgClient->sendMessage($domain, ['from' => $from, 'to' => $to, 'subject' => $subject, 'text' => $text]); } catch (Exception $e) { file_put_contents(sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . 'email-bugs' . DIRECTORY_SEPARATOR . 'email@' . time(), print_r([$e->getMessage(), $to, $subject, $text], true)); } return $result; }
/** * Sends an email using the Mailgun Email API. * * @return void */ protected function _sendWithMailgun() { list(, $domain) = explode('@', Settings::config()->sendmail_email); $mail = new \Mailgun\Mailgun(Settings::config()->mailgun_api_key); $mail->sendMessage($domain, array('from' => Settings::config()->company_name . ' <' . Settings::config()->sendmail_email . '>', 'to' => $this->email . ' <' . $this->email . '>', 'subject' => $this->subject, 'html' => $this->message)); }
/** * Sends an email using the Mailgun Email API. * * @return void */ protected function _sendWithMailgun() { try { list(, $domain) = explode('@', Settings::config()->transport_email); $mail = new \Mailgun\Mailgun(Settings::config()->transport_token); $mail->sendMessage($domain, array('from' => Settings::config()->company_name . ' <' . Settings::config()->transport_email . '>', 'to' => $this->email . ' <' . $this->email . '>', 'subject' => $this->subject, 'html' => $this->message)); } catch (\Exception $e) { Debugger::log($e); } }
<?php /** * @author Gaaaab */ use App\Http\Model\Contact; use Tamtamchik\SimpleFlash\Flash; $app->get('/contact', function () use($app) { $app->render('site/contacts/contact.php'); })->name('contact.index'); $app->post('/contact', function () use($app) { // Mail $mail = new \Mailgun\Mailgun(MAILGUN_KEY); // Validation $rules = ['name' => ['required', 'alpha', 'min_length(3)', 'max_length(60)'], 'email' => ['email', 'required'], 'content' => ['required']]; $input = ['name' => $app->request->post('name'), 'email' => $app->request->post('email'), 'content' => $app->request->post('content')]; $validation_result = \SimpleValidator\Validator::validate($_POST, $rules); if ($validation_result->isSuccess()) { $contact = new Contact(); $contact->name = $app->request->post('name'); $contact->email = $app->request->post('email'); $contact->content = $app->request->post('content'); // Saving it to database? not necessary but WTH not =3 $contact->save(); $mail->sendMessage(MAILGUN_DOMAIN, array('from' => MAIL_FROM, 'to' => MAIL_TO, 'subject' => 'SHARE SOMETHING SUPPORT: CONTACT RESPONSE', 'text' => 'Contact request from: ' . $app->request->post('name') . '\\n' . 'Email: ' . $app->request->post('email') . '\\n' . 'Content: ' . ' ' . $app->request->post('content'))); $app->redirectTo('site.index'); } else { require_once __DIR__ . '/../errors.php'; } })->name('contact.post');
// $body = '<html><body>'; $body .= '<h1 style="font-size:24px;font-family:sans-serif;">Contact form</h1>'; if (isset($_SERVER['HTTP_REFERER'])) { $body .= '<h2 style="font-size:16px;font-weight:normal;font-family:sans-serif;">' . $_SERVER['HTTP_REFERER'] . '</h2>'; } $body .= '<table cellpadding="0" cellspacing="0" style="border-collapse:collapse;">'; foreach ($_POST as $key => $value) { $body .= "<tr>"; $body .= '<th style="text-align:left;font-family:sans-serif;font-size:12px;padding:5px;border:solid 1px #ccc;">' . htmlspecialchars($key) . "</th>"; $body .= '<td style="text-align:left;font-family:sans-serif;font-size:12px;padding:5px;border:solid 1px #ccc;">' . htmlspecialchars($value) . "</td>"; $body .= "</tr>"; } $body .= "</table>"; $body .= "</body></html>"; // // Send the mail // $mg = new \Mailgun\Mailgun($config['mailgun_api_key']); $mg->sendMessage($config['mailgun_domain'], array('from' => $config['from'], 'to' => $config['to'], 'subject' => $config['subject'], 'html' => $body)); // // What to do on success // if (isset($_GET['redirect'])) { header('Location: ' . $_GET['redirect']); exit; } else { header('Content-type: application/json'); echo json_encode(array('status' => 'ok')); exit; }
public function send($to, $msg, $subject) { $mg = new Mailgun\Mailgun("key-aef6eef0527a56e5826a00fdd9afee3b"); $domain = "genuine-cars.com"; $mg->sendMessage($domain, array('from' => '*****@*****.**', 'to' => $to, 'subject' => $subject, 'text' => $msg)); }
public function payment_return($id, $token) { $this->load->helper('allpay_payment'); $this->load->model('model_booking'); $booking = $this->model_booking->getBooking($id, $token, null, true); if (empty($booking)) { return show_404(); } $this->load->helper('allpay_payment'); include APPPATH . 'config/allpay_payment.php'; try { $aio = new AllInOne(); $aio->ServiceURL = $allpay_config['ServiceURL']; $aio->HashKey = $allpay_config['HashKey']; $aio->HashIV = $allpay_config['HashIV']; $aio->MerchantID = $allpay_config['MerchantID']; $aio_feedback = $aio->CheckOutFeedback(); if (count($aio_feedback > 1)) { switch ($aio_feedback['RtnCode']) { case 1: case 800: //AIO 付款成功 $this->model_booking->editBooking($id, ['paid' => true]); $message = '付款成功'; break; case 2: //ATM 取號成功 $message = "ATM 取號成功:\n繳款銀行代碼:{$aio_feedback['BankCode']}\n繳款虛擬帳號:{$aio_feedback['vAccount']}\n繳費期限:{$aio_feedback['ExpireDate']}"; break; case 10100073: //CVS/BARCODE 取號成功 switch ($aio_feedback['PaymentType']) { case PaymentMethod::CVS: $message = "超商代碼取號成功:\n超商代碼:{$aio_feedback['PaymentNo']}\n繳費期限:{$aio_feedback['ExpireDate']}"; break; case PaymentMethod::BARCODE: $message = "超商條碼取號成功:\n第一段條碼:{$aio_feedback['Barcode1']}\n第二段條碼:{$aio_feedback['Barcode2']}\n第二段條碼:{$aio_feedback['Barcode2']}\n繳費期限:{$aio_feedback['ExpireDate']}"; break; default: throw new Exception('0|Invalid PaymentType'); break; } break; default: throw new Exception('0|Invalid RtnCode'); break; } $this->model_booking->addPayment(['booking' => $id, 'payment_type' => $aio_feedback['PaymentType'], 'amount' => $aio_feedback['TradeAmt'], 'allpay' => $aio_feedback['TradeNo'], 'payment_at' => strtotime($aio_feedback['PaymentDate']), 'created_at' => strtotime($aio_feedback['TradeDate']), 'message' => $message]); //Sending E-Mail: include APPPATH . 'config/mailgun.php'; $mg = new Mailgun\Mailgun($mailgun_config['appkey']); $mg_result = $mg->sendMessage($mailgun_config['domain'], ['from' => $mailgun_config['sender'], 'to' => "{$booking->name} <{$booking->email}>", 'subject' => '付款狀態更新 | 開源!資訊萌芽營', 'text' => "Hi, {$booking->name}!\n您的報名資料付款狀態已更新,詳情如下:\n{$message}\n\nSOSCET, 東部學生開源社群"]); if ($this->input->get('is_browser')) { redirect("event/review/{$id}/{$token}"); } else { $this->output->set_output('1|OK'); } } else { throw new Exception('Return Value Errors'); } } catch (Exception $e) { return show_404(); } }