本文整理汇总了PHP中Mail_mime::addAttachment方法的典型用法代码示例。如果您正苦于以下问题:PHP Mail_mime::addAttachment方法的具体用法?PHP Mail_mime::addAttachment怎么用?PHP Mail_mime::addAttachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mail_mime
的用法示例。
在下文中一共展示了Mail_mime::addAttachment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: emailNotification
/**
* emailNotification()
* creates an email message with the pdf and sends it
*
* @param string pdf binary/string stream
* @param array customer information array
* @param array smtp server information
* @param string from email address of the sender identity
*/
function emailNotification($pdfDocument, $customerInfo, $smtpInfo, $from)
{
global $base;
if (empty($customerInfo['business_email'])) {
return;
}
$headers = array("From" => $from, "Subject" => "User Invoice Notification", "Reply-To" => $from);
$mime = new Mail_mime();
$mime->setTXTBody("Notification letter of service");
$mime->addAttachment($pdfDocument, "application/pdf", "invoice.pdf", false, 'base64');
$body = $mime->get();
$headers = $mime->headers($headers);
$mail =& Mail::factory("smtp", $smtpInfo);
$mail->send($customerInfo['business_email'], $headers, $body);
}
示例2: send_email
private function send_email($to, $subject, $body, $attachments)
{
require_once 'Mail.php';
require_once 'Mail/mime.php';
require_once 'Mail/mail.php';
$headers = array('From' => _EMAIL_ADDRESS, 'To' => $to, 'Subject' => $subject);
// attachment
$crlf = "\n";
$mime = new Mail_mime($crlf);
$mime->setHTMLBody($body);
//$mime->addAttachment($attachment, 'text/plain');
if (is_array($attachments)) {
foreach ($attachments as $attachment) {
$mime->addAttachment($attachment, 'text/plain');
}
}
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp', array('host' => _EMAIL_SERVER, 'auth' => true, 'username' => _EMAIL_USER, 'password' => _EMAIL_PASSWORD));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo "<p>" . $mail->getMessage() . "</p>";
} else {
echo "<p>Message successfully sent!</p>";
}
}
示例3: sendEmail
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);
}
}
}
示例4: sendMail
function sendMail($absender_email, $absender_name, $Empfaenger, $Betreff, $content, $attachments)
{
global $config;
$crlf = "\n";
$from = "{$absender_name} <{$absender_email}>";
$headers = array('From' => $from, 'To' => $Empfaenger, 'Subject' => $Betreff);
$mime = new Mail_mime(array('eol' => $crlf));
$mime->setTXTBody($content);
if (isset($attachments)) {
foreach ($attachments as $attachment) {
if (isset($attachment["filename"]) && $attachment["filename"] != "" && isset($attachment["mailname"]) && $attachment["mailname"] != "") {
$mime->addAttachment($attachment["filename"], 'application/octet-stream', $attachment["mailname"], true, 'base64');
}
}
}
$body = $mime->get(array('html_charset' => 'utf-8', 'text_charset' => 'utf-8', 'eol' => $crlf));
$hdrs = $mime->headers($headers);
$smtp = Mail::factory('smtp', array('host' => $config['smtphost'], 'auth' => true, 'username' => $config['smtpusername'], 'password' => $config['smtppassword']));
$mail = $smtp->send($Empfaenger, $hdrs, $body);
/*
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
*/
// mail($Empfaenger, $Betreff, $text, $Header) or die('Die Email
// konnte nicht versendet werden');
}
示例5: main
public function main()
{
if (empty($this->from)) {
throw new BuildException('Missing "from" attribute');
}
$this->log('Sending mail to ' . $this->tolist);
if (!empty($this->filesets)) {
@(require_once 'Mail.php');
@(require_once 'Mail/mime.php');
if (!class_exists('Mail_mime')) {
throw new BuildException('Need the PEAR Mail_mime package to send attachments');
}
$mime = new Mail_mime(array('text_charset' => 'UTF-8'));
$hdrs = array('From' => $this->from, 'Subject' => $this->subject);
$mime->setTXTBody($this->msg);
foreach ($this->filesets as $fs) {
$ds = $fs->getDirectoryScanner($this->project);
$fromDir = $fs->getDir($this->project);
$srcFiles = $ds->getIncludedFiles();
foreach ($srcFiles as $file) {
$mime->addAttachment($fromDir . DIRECTORY_SEPARATOR . $file, 'application/octet-stream');
}
}
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail = Mail::factory('mail');
$mail->send($this->tolist, $hdrs, $body);
} else {
mail($this->tolist, $this->subject, $this->msg, "From: {$this->from}\n");
}
}
示例6: eMail
function eMail($row, $user = '')
{
$lastRun = $this->getLastReportRun($row['subscription_name']);
$html = $lastRun['report_html'];
if ($html == '' || $html == 'NULL') {
return FALSE;
}
// Remove google chart data
$css = file_get_contents('/var/www/html/css/mail.css');
$message = "<html>\n<head>\n<style>\n{$css}\n</style>\n</head>\n";
$html = str_replace("<td class='chart'>", "<td>", $html);
$sp1 = strpos($html, "<body>");
$sp2 = strpos($html, "<form");
$sp3 = strpos($html, "</form>");
$message .= substr($html, $sp1, $sp2 - $sp1);
$message .= "<p><a href='https://analytics.atari.com/report_log.php?_report=" . $row['subscription_name'] . "&_cache=" . $lastRun['report_startts'] . "'>View This In A Browser</a></p>";
$message .= substr($html, $sp3 + strlen('</form>'));
// Now Email the results
$crlf = "\n";
$hdrs = array('Subject' => "Atari Analytics: Report: " . $row['subscription_title'] . ". Run completed successfully at " . $lastRun['report_endts'] . ".");
$mime = new Mail_mime(array('eol' => $crlf));
$mime->setHTMLBody($message);
$mime->addAttachment("/tmp/" . $lastRun['report_csv'], 'text/plain');
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail =& Mail::factory('mail');
if ($user == '') {
$mail->send($row['subscription_list'], $hdrs, $body);
} else {
$mail->send($user, $hdrs, $body);
}
return TRUE;
}
示例7: send
protected function send($alternateRecipient = null)
{
$mime = new Mail_mime(array("head_charset" => "utf-8", "text_charset" => "utf-8", "html_charset" => "utf-8", 'eol' => "\n"));
$mime->setTXTBody($this->txtBody);
if ($this->htmlBody !== null) {
$mime->setHTMLBody($this->htmlBody);
}
if (!empty($this->attachments)) {
foreach ($this->attachments as $attachment) {
$mime->addAttachment($attachment->File(), $attachment->Type());
}
}
$this->headers['To'] = $this->receipients;
$this->headers['Sender'] = $this->headers['From'];
$empfaenger = $this->receipients;
if ($this->bcc !== null) {
$this->receipients .= ($this->receipients > '' ? ',' : '') . $this->bcc;
}
//do not ever try to call these lines in reverse order
$body = $mime->get();
$headers = $mime->headers($this->headers, true);
if ($this->receipients > '') {
if (!$GLOBALS['Settings']['OnServer']) {
$this->receipients = 'christian@smoice.com';
} elseif ($alternateRecipient) {
$this->receipients = $alternateRecipient;
}
$mail_queue = new Mail_Queue($GLOBALS['Settings']['MailQueue']['db_options'], $GLOBALS['Settings']['MailQueue']['mail_options']);
$mail_queue->put($this->headers['From'], $this->receipients, $headers, $body, $this->delay);
}
return true;
}
示例8: mymail_attach
function mymail_attach($to, $subject, $body, $attach, $attachdata)
{
if (!count($attach) && !count($attachdata)) {
return mymail($to, $subject, $body);
}
require_once "Mail/mime.php";
$json = json_decode(file_get_contents("/home/abhishek/Desktop/GenApp/abhishektest/appconfig.json"));
$headers = array('From' => 'abhishektest@' . $json->mail->from, 'To' => $to, 'Subject' => $subject);
$mime = new Mail_mime(array('eol' => "\n"));
$mime->setTXTBody($body);
if (count($attachdata)) {
ob_start();
foreach ($attach as $f) {
if (!$mime->addAttachment($f, 'text/plain')) {
$mime->addAttachment("could not attach {$f}", 'text/plain', "error-{$f}", false);
}
}
ob_end_clean();
}
if (count($attachdata)) {
ob_start();
foreach ($attachdata as $d) {
if (isset($d['data']) && isset($d['name'])) {
if (!$mime->addAttachment($d['data'], 'text/plain', $d['name'], false)) {
$mime->addAttachment("could not attach data", 'text/plain', $d['name'], false);
}
} else {
$mime->addAttachment("data data or name not set", 'text/plain', "unknown", false);
}
}
ob_end_clean();
}
$body = $mime->get();
$headers = $mime->headers($headers);
if (isset($json->mail->smtp)) {
$smtp = Mail::factory('smtp', array('host' => $json->mail->smtp->host, 'auth' => true, 'username' => $json->mail->smtp->user, 'password' => rtrim(base64_decode($json->mail->smtp->password))));
$mail = $smtp->send($to, $headers, $body);
return PEAR::isError($mail);
}
$phpmail = Mail::factory('mail');
$mail = $phpmail->send($to, $headers, $body);
return PEAR::isError($mail);
}
示例9: SendEmail
/**
* Sends an email
*
* @param array $attachment_files an array containing files to be attached with email.
* @param string $from the sender of the email.
* @param string $to the reciever of the email.
* @param string $subject the subject of the email.
* @param string $message the message of the email.
* @throws Exception throws an exception if the file size is greater than a limit or the file extension is not valid or the uploaded file could not be copied
*
* @return boolean $is_sent used to indicate if the email was sent.
*/
public function SendEmail($attachment_files, $from, $to, $subject, $text)
{
try {
/** The email text is encoded */
$processed = htmlentities($text);
/** If the encoded text is same as the original text then the text is considered to be plain text */
if ($processed == $text) {
$is_html = false;
} else {
$is_html = true;
}
/** If the attachment files were given */
if (is_array($attachment_files)) {
/** Mail_mine object is created */
$message = new \Mail_mime();
/** If the message is not html */
if (!$is_html) {
$message->setTXTBody($text);
} else {
$message->setHTMLBody($text);
}
/** Each given file is attached */
for ($count = 0; $count < count($attachment_files); $count++) {
$path_of_uploaded_file = $attachment_files[$count];
if ($path_of_uploaded_file != "") {
$message->addAttachment($path_of_uploaded_file);
}
}
/** The message body is fetched */
$body = $message->get();
/** The extra headers */
$extraheaders = array("From" => $from, "Subject" => $subject, "Reply-To" => $from);
/** The email headers */
$headers = $message->headers($extraheaders);
} else {
/** The message body */
$body = $text;
/** The message headers */
$headers = array("From" => $from, "Subject" => $subject, "Reply-To" => $from);
}
/** The Mail class object is created */
$mail = new \Mail("mail");
/** The email is sent */
$is_sent = $mail->send($to, $headers, $body);
if (!$is_sent) {
throw new \Exception("Email could not be sent. Details: " . $e->getMessage());
} else {
return true;
}
} catch (\Exception $e) {
throw new \Exception("Email could not be sent. Details: " . $e->getMessage());
}
}
示例10: send
public function send($to, $subject, $body, $type = null, $headers = null, $attachments = null)
{
if (is_null($type)) {
$type = 'text';
}
if (is_null($headers)) {
$headers = array();
}
$to = str_replace(';', ',', $to);
if (!isset($headers['From'])) {
$headers['From'] = $this->getConf('default_from');
}
if (!isset($headers['To'])) {
$headers['To'] = $to;
}
$headers['Subject'] = $subject;
$required_headers = array('From', 'Subject');
foreach ($required_headers as $field) {
if (!@$headers[$field]) {
throw new Exception("Must have a '{$field}' header.");
}
}
// start
$mime = new Mail_mime("\n");
switch ($type) {
case 'text':
$mime->setTXTBody($body);
break;
case 'html':
$mime->setHTMLBody($body);
break;
}
if (is_array($attachments)) {
$defaults = array('type' => 'application/octet-stream', 'name' => '', 'isfile' => true, 'encoding' => 'base64');
foreach ($attachments as $attachment) {
if (!isset($attachment['file'])) {
throw new Exception("Attachment missing 'file' field.");
}
$a = array_merge($defaults, $attachment);
$res = $mime->addAttachment($a['file'], $a['type'], $a['name'], $a['isfile'], $a['encoding']);
}
}
// order is important
$b = $mime->get();
$h = $mime->headers($headers);
$res = $this->mail->send($to, $h, $b);
if (PEAR::isError($res)) {
throw new Exception('Could not send email (' . $res->getMessage() . ' - ' . $res->getUserinfo() . ')');
}
}
示例11: sendMail
function sendMail($to, $subject, $mailText, $from = "", $type = "", $prozess = 1)
{
Logger::getInstance()->Log($to, LOG_ABLAUF);
$message = new Mail_mime("\n");
// watt isn dat hier für ne funktion? die macht mit sicherheit alles, aber keinen html-Body
$message->setHTMLBody($mailText);
if ($this->attachement != null)
{
foreach ($this->attachement AS $attachment)
$messageatt = $message->addAttachment($attachment);
//Logger::getInstance()->Log($messageatt,LOG_ABLAUF);
$this->attachement = null;
}
if (empty($from))
$header['From'] = $this->from;
else
$header['From'] = $from;
$header['Subject'] = $subject;
$header['To'] = $to;
$header['Date'] = date("D, d M Y H:i:s O");
$header['Message-ID'] = '<' . time() . '.' . $prozess . '@' . $this->host . '>';
$messBody = $message->get(array("text_encoding" => "quoted-printable"));
if ($type == 'html')
$messBody = '<html><body>' . $messBody . '</body></html>';
$header2 = $message->headers($header);
$error_obj = self::$mailer->send($to, $header2, $messBody);
if (is_object($error_obj))
{
//Logger::getInstance()->Log($message, LOG_ABLAUF);
$errorString = ob_get_contents();
file_put_contents(PATH . 'mail.error.log', $errorString);
return false;
}
else
{
//z('email was send successfully!');
return true;
}
}
示例12: sendWelcomeNotification
/**
* sendWelcomeNotification()
* wrapper-function to send notification to the customer
*
* @param array customer information array
* @param array smtp server information
* @param string from email address of the sender identity
*/
function sendWelcomeNotification($customerInfo, $smtpInfo, $from)
{
global $base;
if (empty($customerInfo['customer_email'])) {
return;
}
$headers = array("From" => $from, "Subject" => "Welcome new customer!", "Reply-To" => $from);
$html = prepareNotificationTemplate($customerInfo);
$pdfDocument = createPDF($html);
$mime = new Mail_mime();
$mime->setTXTBody("Notification letter of service");
$mime->addAttachment($pdfDocument, "application/pdf", "notification.pdf", false, 'base64');
$body = $mime->get();
$headers = $mime->headers($headers);
$mail =& Mail::factory("smtp", $smtpInfo);
$mail->send($customerInfo['customer_email'], $headers, $body);
}
示例13: send
/**
* Método que envía el correo
* @return Arreglo con los estados de retorno por cada correo enviado
* @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl)
* @version 2016-05-12
*/
public function send()
{
// Crear correo
$mailer = \Mail::factory('smtp', $this->_config);
$mail = new \Mail_mime();
// Asignar mensaje
$mail->setTXTBody($this->_data['text']);
$mail->setHTMLBody($this->_data['html']);
// Si existen archivos adjuntos agregarlos
if (!empty($this->_data['attach'])) {
foreach ($this->_data['attach'] as &$file) {
$result = $mail->addAttachment(isset($file['tmp_name']) ? $file['tmp_name'] : $file['data'], $file['type'], $file['name'], isset($file['tmp_name']) ? true : false);
if (is_a($result, 'PEAR_Error')) {
return ['type' => $result->getType(), 'code' => $result->getCode(), 'message' => $result->getMessage()];
}
}
}
// cuerpo y cabecera con codificación en UTF-8
$body = $mail->get(['text_encoding' => '8bit', 'text_charset' => 'UTF-8', 'html_charset' => 'UTF-8', 'head_charset' => 'UTF-8', 'head_encoding' => '8bit']);
// debe llamarse antes de headers
$to = implode(', ', $this->_header['to']);
$headers_data = ['From' => $this->_header['from'], 'To' => $to, 'Subject' => $this->_header['subject']];
if (!empty($this->_header['cc'])) {
$headers_data['Cc'] = implode(', ', $this->_header['cc']);
}
if (!empty($this->_header['replyTo'])) {
//$headers_data['Reply-To'] = $headers_data['Return-Path'] = $this->_header['replyTo'];
$headers_data['Reply-To'] = $this->_header['replyTo'];
}
$headers = $mail->headers($headers_data);
if (!empty($this->_header['cc'])) {
$to .= ', ' . implode(', ', $this->_header['cc']);
}
if (!empty($this->_header['bcc'])) {
$to .= ', ' . implode(', ', $this->_header['bcc']);
}
// Enviar correo a todos los destinatarios
$result = $mailer->send($to, $headers, $body);
// retornar estado del envío del mensaje
if (is_a($result, 'PEAR_Error')) {
return ['type' => $result->getType(), 'code' => $result->getCode(), 'message' => $result->getMessage()];
} else {
return true;
}
}
示例14: sendEmail
public function sendEmail($sSubject, $sReceipients, $sFrom, $sBody, $sAttachmentPath = null)
{
$text = strip_tags($sBody);
$html = $sBody;
if ($sAttachmentPath != null) {
$file = $sAttachmentPath;
}
$crlf = "\n";
$hdrs = array('From' => $sFrom, 'Subject' => $sSubject);
$mime = new Mail_mime(array('eol' => $crlf));
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file, 'text/plain');
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail =& Mail::factory('mail');
$mail->send($sReceipients, $hdrs, $body);
}
示例15: generate_xml_email_kb_main_debug
function generate_xml_email_kb_main_debug($firstName, $lastName, $email, $phone, $comment)
{
error_reporting(E_ALL);
ini_set('display_errors', '1');
// if ($_SERVER['HTTP_HOST'] !== 'www.inspirada.com') return;
require_once "Mail.php";
require_once "Mail/mime.php";
$to = 'mike@aliasproject.com';
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
$xml .= '<hsleads>' . PHP_EOL;
$xml .= '<lead>' . PHP_EOL;
$xml .= '<submit_date_time>' . str_replace('+00:00', '', date('c', strtotime('now'))) . '</submit_date_time>' . PHP_EOL;
$xml .= '<firstname>' . substr($firstName, 0, 15) . '</firstname>' . PHP_EOL;
$xml .= '<lastname>' . substr($lastName, 0, 40) . '</lastname>' . PHP_EOL;
$xml .= '<email>' . substr($email, 0, 40) . '</email>' . PHP_EOL;
$xml .= '<phone>' . substr(preg_replace("/[^0-9]/", "", $phone), 0, 10) . '</phone>' . PHP_EOL;
$xml .= '<message>' . substr($comment, 0, 2048) . '</message>' . PHP_EOL;
$xml .= '<buildernumber>00850</buildernumber>' . PHP_EOL;
$xml .= '<builderreportingname>Las Vegas</builderreportingname>' . PHP_EOL;
$xml .= '<communitynumber></communitynumber>' . PHP_EOL;
$xml .= '</lead>' . PHP_EOL;
$xml .= '</hsleads>';
$from = "Inspirada <info@inspirada.com>";
$subject = "Inspirada - Henderson - Info Requested";
$host = "smtp.gmail.com";
$port = '465';
$username = "InspiradaHenderson@gmail.com";
$password = "0bbLsE9fRXGU";
$headers = array('From' => $from, 'To' => $to, 'Subject' => $subject);
// Format Message
$body = '';
$mime = new Mail_mime();
$mime->setHTMLBody($body);
$xmlobj = new SimpleXMLElement($xml);
$xmlobj->asXML(ABSPATH . 'wp-content/plugins/property-finder/public/export/' . time() . '.xml');
$mime->addAttachment(ABSPATH . 'wp-content/plugins/property-finder/public/export/' . time() . '.xml', 'text/xml');
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp', array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $body);
return PEAR::isError($mail) ? false : true;
}