function sendEmail() { foreach ($this->to as $to) { $headers = array('From' => SMTP_FROM_NAME . "<" . SMTP_FROM . ">", 'To' => $to, 'Subject' => $this->subject); $mime = new Mail_mime($this->NEW_LINE); if ($this->body == null) { if ($this->compiledTXT != null && strlen($this->compiledTXT) > 0) { $mime->setTXTBody($this->compiledTXT); } if ($this->compiledHTML != null && strlen($this->compiledHTML) > 0) { $mime->setHTMLBody($this->compiledHTML); } } else { $mime->setTXTBody($this->body); } foreach ($this->cc as $email) { $mime->addCc($email); } foreach ($this->bcc as $email) { $mime->addBcc($email); } if (is_array($this->files) && count($this->files) > 0) { foreach ($this->files as $file) { $mime->addAttachment($file["path"], $file["content-type"]); } } $body = $mime->get(); $headers = $mime->headers($headers); $string = ""; foreach ($headers as $key => $value) { $string .= "{$key}: {$value}\r\n"; } $smtpOptions = array('host' => SMTP_HOST, 'port' => SMTP_PORT); if (defined("SMTP_USER_NAME") && defined("SMTP_PASSWORD")) { $smtpOptions['auth'] = true; $smtpOptions['username'] = SMTP_USER_NAME; $smtpOptions['password'] = SMTP_PASSWORD; } /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $smtp = Mail::factory('smtp', $smtpOptions); $success = $smtp->send($to, $headers, $body); if ($success !== true) { throw new PEARErrorException($success); } } }
public function send() { $fullFrom = "'" . $this->fromName . "' <" . $this->from . ">"; $fullFrom = $this->from; $cc = NULL; $bcc = NULL; if (is_array($this->to)) { $entries = count($this->to); if ($entries > 1) { $to = ""; $counter = 0; foreach ($this->to as $address) { $chk = $counter + 1; if ($chk == $entries) { $to .= $address; } else { $to .= $address . ','; } $counter++; } } else { $to = $this->to[0]; } } else { $to = $this->to; } $recipients = $to; // Add CC if (isset($this->cc)) { if (is_array($this->cc)) { $entries = count($this->cc); $cc = ""; $counter = 0; foreach ($this->cc as $address) { $chk = $counter + 1; if ($chk == $entries) { $cc .= $address; } else { $cc .= $address . ','; } $counter++; } } else { $cc = $this->cc; } $recipients = $recipients . "," . $cc; } // Add CC if (isset($this->bcc)) { if (is_array($this->bcc)) { $entries = count($this->bcc); $bcc = ""; $counter = 0; foreach ($this->bcc as $address) { $chk = $counter + 1; if ($chk == $entries) { $bcc .= $address; } else { $bcc .= $address . ','; } $counter++; } } else { $bcc = $this->cc; } $recipients = $recipients . "," . $bcc; } // To Blind CC (aka, BCC) an address, simply add the address to the // $recipients, but not to any of the $headers. $headers = array('From' => $fullFrom, 'Return-Path' => $this->from, 'To' => $to, 'Cc' => $cc, 'Subject' => $this->subject); //setting values for htmlMail switch ($this->useHTMLMail) { case TRUE: $objMime = new Mail_mime(); $objMime->addCc($this->cc); $objMime->addBcc($this->bcc); $objMime->setTXTBody($this->body); $objMime->setHTMLBody($this->htmlbody); $this->body = $objMime->get(); $headers = $objMime->headers($headers); // $smptParams = array('MIME Version' => '1.0', 'Content-Type' => 'text/html; charset=ISO-8859-1', 'host' => $this->host, 'port' => $this->port, 'auth' => $this->smtpAuth, 'username' => $this->username, 'password' => $this->password); // $smtp = Mail::factory('smtp', $smptParams); break; default: $smtp = Mail::factory('smtp', array('host' => $this->host, 'port' => $this->port, 'auth' => $this->smtpAuth, 'username' => $this->username, 'password' => $this->password)); break; } $mail = $smtp->send($recipients, $headers, $this->body); if (PEAR::isError($mail)) { echo "<p>" . $mail->getMessage() . "</p>"; return FALSE; } else { return TRUE; } }
$client->setAccessToken($_SESSION['access_token']); } else { $loginUrl = $client->createAuthUrl(); } // Check if we have an access token ready for API calls try { if (isset($_SESSION['access_token']) && $client->getAccessToken()) { // Make API Calls if (isset($_POST['send'])) { $to = $_POST['to']; $bcc = $_POST['bcc']; $cc = $_POST['cc']; $body = $_POST['message']; $subject = $_POST['subject']; $mime->addTo($to); $mime->addBcc($bcc); $mime->addCc($cc); $mime->setTXTBody($body); $mime->setHTMLBody($body); $mime->setSubject($subject); $message_body = $mime->getMessage(); $encoded_message = base64url_encode($message_body); // Gmail Message Body $message = new Google_Service_Gmail_Message(); $message->setRaw($encoded_message); // Send the Email $email = $service->users_messages->send('me', $message); if ($email->getId()) { $notice = '<div class="alert alert-success">Email Sent successfully!</div>'; } else { $notice = '<div class="alert alert-danger">Oops...something went wrong, try again later</div>';
function process() { //include PEAR mailing class include_once 'Mail.php'; include_once 'Mail/mime.php'; $mime = new Mail_mime($this->crlf); $mail = Mail::factory('mail'); //set encoding $mime->_build_params['head_charset'] = $mime->_build_params['text_charset'] = $mime->_build_params['html_charset'] = $this->charset; //set from, subject $hdrs = array('From' => $this->from, 'Subject' => $this->subject); //set to if (count($this->adresses['to']) > 0) { $to = implode(', ', $this->adresses['to']); } else { return false; } //set cc if (count($this->adresses['cc']) > 0) { $mime->addCc(implode(', ', $this->adresses['cc'])); } //set bcc if (count($this->adresses['bcc']) > 0) { $mime->addBcc(implode(', ', $this->adresses['bcc'])); } //add attachments foreach ($this->attachments as $v) { $mime->addAttachment($v['file'], $v['type'], $v['name']); } //set message $mime->setTXTBody($this->txt_body); $body = $mime->get(); $hdrs = $mime->headers($hdrs); $mail = Mail::factory('mail'); return $mail->send($to, $hdrs, $body); //$mail->send(array($to), 'mail'); }
/** * Send the mail, based on the class' properties. * * @return bool */ public function send() { // Validate properties and throw an exception for errors $this->validate(); // Add text variant when only HTTML is provided if ($this->messageTxt === null) { $this->messageTxt = html_entity_decode($this->messageHtml); } // Send the mail $headers = ['From' => $this->from, 'Subject' => $this->subject]; $mime = new \Mail_mime(PHP_EOL); $mime->setTXTBody($this->messageTxt); $mime->setHTMLBody($this->messageHtml); if (!empty($this->cc)) { foreach ($this->cc as $address) { $mime->addCc($address); } } if (!empty($this->bcc)) { foreach ($this->bcc as $address) { $mime->addBcc($address); } } $result = (new \Mail_mail())->send($this->address, $mime->headers($headers), $mime->get(['text_charset' => 'utf-8', 'html_charset' => 'utf-8'])); return !is_a($result, 'PEAR_Error'); }
public function main() { $mime = new Mail_mime(); // Add message as html or plain text if ($this->isHtml()) { $mime->setHTMLBody($this->getMessage()); } else { $mime->setTXTBody($this->getMessage()); } // Add recipients foreach ($this->getTo() as $recipient) { $mime->addTo($recipient); } foreach ($this->getCc() as $recipient) { $mime->addCc($recipient); } foreach ($this->getBcc() as $recipient) { $mime->addBcc($recipient); } // Add sender and subject $mime->setFrom($this->getFrom()); $mime->setSubject($this->getSubject()); // Send the damnedable thing! $body = $mime->get(); $headers = $mime->headers(); $this->log("Assembled headers: " . print_r($headers, true)); $mail =& Mail::factory('mail'); $status = $mail->send($this->getTo(), $headers, $body); // Handle the outcome of our send attempt if ($status === true) { $recipCount = count($this->getTo()) + count($this->getCc()) + count($this->getBcc()); $this->log("Sent MIME mail to {$recipCount} recipients"); } else { throw new BuildException('Failed to send MIME mail: ' . $status->getMessage()); } }