$subject = 'You have received a new personal message!'; $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array('host' => SMTP_SERVER, 'auth' => SMTP_AUTHENTICATION, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD)); $message = '<html><body>'; $message .= '<p>Hello ' . $to_name . ',</p>'; $message .= '<p>You have just received a new message from ' . $name . '! '; $message .= '<a href="' . BASE_URI . '/messages">Click here</a> to see it.</p>'; $message .= '<br/><p><small>You are receiving this email because you enabled Semantic Pingback notification '; $message .= '(with email as notification mechanism) for your Personal Profile on <a href="' . BASE_URI . '">' . BASE_URI . '</a>. '; $message .= 'If you would like to stop receiving email notifications, please check your '; $message .= ' <a href="' . BASE_URI . '/subscription.php">subscription settings</a>.</small></p>'; $message .= '<p><small>You do not need to respond to this automated email.</small></p>'; $message .= '</body></html>'; $crlf = "\n"; $mime = new Mail_Mime(array('eol' => $crlf)); $mime->setHTMLBody($message); $mimeparams = array(); $mimeparams['html_charset'] = "UTF-8"; $mimeparams['head_charset'] = "UTF-8"; $headers = $mime->headers($headers); $body = $mime->get($mimeparams); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { $ret .= error('Sendmail: ' . $mail->getMessage()); } } // Everything is OK, return a proper HTTP response success code $ret .= header("HTTP/1.1 201 Created"); $ret .= header("Status: 201 Created"); $ret .= "<html><body>\n"; $ret .= "Your message has been successfully delivered!\n";
/** * Send an automated response. * * @param object $mailing * The mailing object. * @param int $queue_id * The queue ID. * @param string $replyto * Optional reply-to from the reply. * * @return void */ private static function autoRespond(&$mailing, $queue_id, $replyto) { $config = CRM_Core_Config::singleton(); $contacts = CRM_Contact_DAO_Contact::getTableName(); $email = CRM_Core_DAO_Email::getTableName(); $queue = CRM_Mailing_Event_DAO_Queue::getTableName(); $eq = new CRM_Core_DAO(); $eq->query("SELECT {$contacts}.preferred_mail_format as format,\n {$email}.email as email,\n {$queue}.job_id as job_id,\n {$queue}.hash as hash\n FROM {$contacts}\n INNER JOIN {$queue} ON {$queue}.contact_id = {$contacts}.id\n INNER JOIN {$email} ON {$queue}.email_id = {$email}.id\n WHERE {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer')); $eq->fetch(); $to = empty($replyto) ? $eq->email : $replyto; $component = new CRM_Mailing_BAO_Component(); $component->id = $mailing->reply_id; $component->find(TRUE); $message = new Mail_Mime("\n"); $domain = CRM_Core_BAO_Domain::getDomain(); list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail(); $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); $headers = array('Subject' => $component->subject, 'To' => $to, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}"); /* TODO: do we need reply tokens? */ $html = $component->body_html; if ($component->body_text) { $text = $component->body_text; } else { $text = CRM_Utils_String::htmlToText($component->body_html); } $bao = new CRM_Mailing_BAO_Mailing(); $bao->body_text = $text; $bao->body_html = $html; $tokens = $bao->getTokens(); if ($eq->format == 'HTML' || $eq->format == 'Both') { $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']); $html = CRM_Utils_Token::replaceMailingTokens($html, $mailing, NULL, $tokens['html']); $message->setHTMLBody($html); } if (!$html || $eq->format == 'Text' || $eq->format == 'Both') { $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']); $text = CRM_Utils_Token::replaceMailingTokens($text, $mailing, NULL, $tokens['text']); $message->setTxtBody($text); } $b = CRM_Utils_Mail::setMimeParams($message); $h = $message->headers($headers); CRM_Mailing_BAO_Mailing::addMessageIdHeader($h, 'a', $eq->job_id, queue_id, $eq->hash); $mailer = $config->getMailer(); if (is_object($mailer)) { $errorScope = CRM_Core_TemporaryErrorScope::ignoreException(); $mailer->send($to, $h, $b); unset($errorScope); } }
/** * Send the email out. * @return err 0 if no error; otherwise a PEAR_Error object with the error. */ function send() { // sanity check required pieces if (empty($this->to_email)) { return PEAR::raiseError('to email cannot be empty.'); } if (empty($this->from_email)) { return PEAR::raiseError('from email cannot be empty.'); } // set up all headers $headers = array(); $recipients = $this->getRecipients(); $headers["To"] = join(", ", $recipients['To']); if (count($recipients['Cc'])) { $headers["Cc"] = join(", ", $recipients['Cc']); } if (count($recipients['Bcc'])) { $headers["Bcc"] = join(", ", $recipients['Bcc']); } // FROM if ($this->from_name != '') { $headers["From"] = "\"{$this->from_name}\" <{$this->from_email}>"; } else { $headers["From"] = "{$this->from_email}"; } // REPLY-TO if ($this->reply_to_email != '') { $headers["Reply-To"] = "{$this->reply_to_email}"; } // PRIORITY $headers["X-Priority"] = "{$this->priority}"; // SUBJECT $headers["Subject"] = $this->subject; // ENVELOPE ADDRESS - make things bounce to the right place $headers["Return-Path"] = $headers["Errors-To"] = "{$this->from_email}"; $headers["Errors-To"] = "{$this->from_email}"; // Add an x-mailer; reduces chance of being flagged as SPAM $headers["X-Mailer"] = "PHOCOA Web Framework Mailer"; // Right before we pull the body text/html, HTMLify the message if it // meets the criteria for HTMLification. This function does nothing // if htmlify_plain_text_only_messages is turned off. $this->htmlify(); // use PEAR::Mail_Mime to format message $mm = new Mail_Mime(); @$mm->setTXTBody($this->raw_message_text); if ($this->raw_message_html) { @$mm->setHTMLBody($this->raw_message_html); } // add attachments foreach ($this->attachments as $attachment_info) { $err = @$mm->addAttachment($attachment_info['file'], $attachment_info['type'], $attachment_info['name'], $attachment_info['isfile']); if (PEAR::isError($err)) { return $err; } } $mm_body = @$mm->get(); $mm_headers = @$mm->headers($headers); if (is_null($this->pear_mailer_config)) { $mailer =& Mail::factory($this->pear_mailer_driver); } else { $mailer =& Mail::factory($this->pear_mailer_driver, $this->pear_mailer_config); } if (PEAR::isError($mailer)) { return $mailer; } $err = @$mailer->send(array_keys($recipients['All']), $mm_headers, $mm_body); if (PEAR::isError($err)) { return $err; } return 0; }
/** * Send an automated response * * @param object $mailing The mailing object * @param int $queue_id The queue ID * @param string $replyto Optional reply-to from the reply * @return void * @access private * @static */ private static function autoRespond(&$mailing, $queue_id, $replyto) { $config = CRM_Core_Config::singleton(); $contacts = CRM_Contact_DAO_Contact::getTableName(); $email = CRM_Core_DAO_Email::getTableName(); $queue = CRM_Mailing_Event_DAO_Queue::getTableName(); $eq = new CRM_Core_DAO(); $eq->query("SELECT {$contacts}.preferred_mail_format as format,\n {$email}.email as email\n FROM {$contacts}\n INNER JOIN {$queue} ON {$queue}.contact_id = {$contacts}.id\n INNER JOIN {$email} ON {$queue}.email_id = {$email}.id\n WHERE {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer')); $eq->fetch(); $to = empty($replyto) ? $eq->email : $replyto; $component = new CRM_Mailing_BAO_Component(); $component->id = $mailing->reply_id; $component->find(true); $message = new Mail_Mime("\n"); require_once 'CRM/Core/BAO/Domain.php'; $domain =& CRM_Core_BAO_Domain::getDomain(); list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail(); require_once 'CRM/Core/BAO/MailSettings.php'; $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); $headers = array('Subject' => $component->subject, 'To' => $to, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}"); /* TODO: do we need reply tokens? */ $html = $component->body_html; if ($component->body_text) { $text = $component->body_text; } else { $text = CRM_Utils_String::htmlToText($component->body_html); } require_once 'CRM/Mailing/BAO/Mailing.php'; $bao = new CRM_Mailing_BAO_Mailing(); $bao->body_text = $text; $bao->body_html = $html; $tokens = $bao->getTokens(); if ($eq->format == 'HTML' || $eq->format == 'Both') { require_once 'CRM/Utils/Token.php'; $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true, $tokens['html']); $html = CRM_Utils_Token::replaceMailingTokens($html, $mailing, null, $tokens['html']); $message->setHTMLBody($html); } if (!$html || $eq->format == 'Text' || $eq->format == 'Both') { require_once 'CRM/Utils/Token.php'; $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false, $tokens['text']); $text = CRM_Utils_Token::replaceMailingTokens($text, $mailing, null, $tokens['text']); $message->setTxtBody($text); } $b =& CRM_Utils_Mail::setMimeParams($message); $h =& $message->headers($headers); $mailer =& $config->getMailer(); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler')); if (is_object($mailer)) { $mailer->send($to, $h, $b); CRM_Core_Error::setCallback(); } }
echo 'Mail has sent successfully'; } } */ $subject = "Heartweb Subscription"; $mime = new Mail_Mime(); $text = "Hi<BR><BR>"; $text .= "Your subscription to the Heartweb application is due for renewal in 7days. TIf you would liek to carry on with your subscription then you will need renew through the application.<BR>"; $text .= "====== IMPORTANT INFORMATION =========<BR>"; $text .= "Please Note <BR>"; $text .= "The information contained within this report is of a confidential nature and should not be shared with any other person."; // text and html versions of email. $html = '<html><body>' . $text . '</body></html>'; $mime->setTXTBody($text); $mime->setHTMLBody($html); $mime->setFrom(SMTP_USER); $mime->setSubject($subject); $body = $mime->get(); $headers = $mime->headers(); $smtp = Mail::factory('smtp', array('host' => SMTP_HOST, 'port' => SMTP_PORT, 'auth' => true, 'username' => SMTP_USER, 'password' => SMTP_PASSWORD)); foreach ($return as $row) { $mailto = $row['username']; if (TRIM($mailto) != '') { $mailto = $smtp->send($mailto, $header, $body); } if (PEAR::isError($mail)) { echo 'Mail not send'; } else { echo 'Mail has sent successfully'; }
function recover($webid) { // hexa string of 20 chars $hash = sha1(trim($webid) . uniqid(microtime(true), true)); $webid = trim($webid); // find if a recovery email exists or not for the given WebID $query = "SELECT email FROM recovery WHERE webid='" . mysql_real_escape_string($webid) . "'"; $result = mysql_query($query); if (!$result) { die('Unable to connect to the database!'); } else { if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); $email = $row['email']; mysql_free_result($result); // set the hash $query = "UPDATE recovery SET " . "recovery_hash='" . $hash . "' " . "WHERE webid='" . mysql_real_escape_string($webid) . "'"; $result = mysql_query($query); if (!$result) { return error('Unable to connect to the database!'); } else { // send the email $person = new MyProfile(trim($webid), BASE_URI, SPARQL_ENDPOINT); $person->load(); $to_name = $person->get_name(); $from = 'MyProfile Recovery System <' . SMTP_USERNAME . '>'; $to = '"' . $to_name . '" <' . clean_mail($email) . '>'; $subject = 'Instructions to recover your account on ' . BASE_URI . '.'; $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array('host' => SMTP_SERVER, 'auth' => SMTP_AUTHENTICATION, 'username' => SMTP_USERNAME, 'password' => SMTP_PASSWORD)); $message = '<html><body>'; $message .= '<p>Hello ' . $to_name . ',</p>'; $message .= '<p>You have requested to recover your personal account on ' . BASE_URI . '. '; $message .= 'Please click <a href="' . BASE_URI . '/recovery?recovery_code=' . $hash . '">' . BASE_URI . '/recovery?recovery_code=' . $hash . '</a> to proceed.</p>'; $message .= '<p>Alternatively, you can recover your account by visiting this page: <a href="' . BASE_URI . '/recovery">' . BASE_URI . '/recovery</a> and typing or pasting the following recovery code:</p>'; $message .= '<p>'; $message .= '<strong>' . $hash . '</strong> '; $message .= '</p>'; $message .= '<p>Important! Do not forget that once you are logged in, you can obtain a new certificate by going to your <a href="https://my-profile.eu/view">profile page</a> and then clicking on the "Certificate" icon under "Actions for this profile".</p>'; $message .= '<br /><p><hr /></p>'; $message .= '<p><small>This is an automated email generate by <a href="https://my-profile.eu/">MyProfile</a> and you do not need to respond to it.</small></p>'; $message .= '</body></html>'; $crlf = "\n"; $mime = new Mail_Mime(array('eol' => $crlf)); $mime->setHTMLBody($message); $mimeparams = array(); $mimeparams['html_charset'] = "UTF-8"; $mimeparams['head_charset'] = "UTF-8"; $headers = $mime->headers($headers); $body = $mime->get($mimeparams); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { $ret .= error('Sendmail: ' . $mail->getMessage()); } return success('An email has been sent to the recovery address you have specified.'); } } else { return error('You did not provide a recovery email address!'); } } }