本文整理汇总了PHP中Swift_Message::setId方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Message::setId方法的具体用法?PHP Swift_Message::setId怎么用?PHP Swift_Message::setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Message
的用法示例。
在下文中一共展示了Swift_Message::setId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
//.........这里部分代码省略.........
while ($it->hasNext()) {
$it->next();
$address = $it->getValue();
$cc[] = $address->build();
try {
$this->command("RCPT TO: " . $address->build(true), 250);
$tmp_sent++;
} catch (Swift_BadResponseException $e) {
$failed++;
$send_event->addFailedRecipient($address->getAddress());
if ($log->hasLevel(Swift_Log::LOG_FAILURES)) {
$log->addfailedRecipient($address->getAddress());
}
}
}
if ($failed == count($to) + count($cc)) {
$this->reset();
$this->notifyListeners($send_event, "SendListener");
return 0;
}
if (!($has_to = $message->getTo()) && !empty($to)) {
$message->setTo($to);
}
if (!($has_cc = $message->getCc()) && !empty($cc)) {
$message->setCc($cc);
}
$this->command("DATA", 354);
$data = $message->build();
while (false !== ($bytes = $data->read())) {
$this->command($bytes, -1);
}
if ($log->hasLevel(Swift_Log::LOG_NETWORK)) {
$log->add("<MESSAGE DATA>", Swift_Log::COMMAND);
}
try {
$this->command("\r\n.", 250);
$sent += $tmp_sent;
} catch (Swift_BadResponseException $e) {
$failed += $tmp_sent;
}
$tmp_sent = 0;
$has_bcc = $message->getBcc();
$it = $list->getIterator("bcc");
while ($it->hasNext()) {
$it->next();
$address = $it->getValue();
if (!$has_bcc) {
$message->setBcc($address->build());
}
try {
$this->command("MAIL FROM: " . $message->getReturnPath(true), 250);
$this->command("RCPT TO: " . $address->build(true), 250);
$this->command("DATA", 354);
$data = $message->build();
while (false !== ($bytes = $data->read())) {
$this->command($bytes, -1);
}
if ($log->hasLevel(Swift_Log::LOG_NETWORK)) {
$log->add("<MESSAGE DATA>", Swift_Log::COMMAND);
}
$this->command("\r\n.", 250);
$sent++;
} catch (Swift_BadResponseException $e) {
$failed++;
$send_event->addFailedRecipient($address->getAddress());
if ($log->hasLevel(Swift_Log::LOG_FAILURES)) {
$log->addfailedRecipient($address->getAddress());
}
$this->reset();
}
}
$total = count($to) + count($cc) + count($list->getBcc());
$send_event->setNumSent($sent);
$this->notifyListeners($send_event, "SendListener");
if (!$has_return_path) {
$message->setReturnPath("");
}
if (!$has_from) {
$message->setFrom("");
}
if (!$has_to) {
$message->setTo("");
}
if (!$has_reply_to) {
$message->setReplyTo(null);
}
if (!$has_cc) {
$message->setCc(null);
}
if (!$has_bcc) {
$message->setBcc(null);
}
if (!$has_message_id) {
$message->setId(null);
}
if ($log->hasLevel(Swift_Log::LOG_NETWORK)) {
$log->add("Message sent to " . $sent . "/" . $total . " recipients", Swift_Log::NORMAL);
}
return $sent;
}
示例2: setId
/**
* {@inheritdoc}
*
* @return $this|self
*/
public function setId($id) : self
{
$this->message->setId($id);
return $this;
}
示例3: Send
//.........这里部分代码省略.........
}
if (!empty($configuration['PS_MAIL_PASSWD'])) {
$connection->setPassword($configuration['PS_MAIL_PASSWD']);
}
} else {
$connection = new Swift_Connection_NativeMail();
}
if (!$connection) {
return false;
}
$swift = new Swift($connection, Configuration::get('PS_MAIL_DOMAIN', null, null, $id_shop));
/* Get templates content */
$iso = Language::getIsoById((int) $id_lang);
if (!$iso) {
Tools::dieOrLog(Tools::displayError('Error - No ISO code for email'), $die);
return false;
}
$template = $iso . '/' . $template;
$module_name = false;
$override_mail = false;
// get templatePath
if (preg_match('#' . __PS_BASE_URI__ . 'modules/#', str_replace(DIRECTORY_SEPARATOR, '/', $template_path)) && preg_match('#modules/([a-z0-9_-]+)/#ui', str_replace(DIRECTORY_SEPARATOR, '/', $template_path), $res)) {
$module_name = $res[1];
}
if ($module_name !== false && (file_exists($theme_path . 'modules/' . $module_name . '/mails/' . $template . '.txt') || file_exists($theme_path . 'modules/' . $module_name . '/mails/' . $template . '.html'))) {
$template_path = $theme_path . 'modules/' . $module_name . '/mails/';
} elseif (file_exists($theme_path . 'mails/' . $template . '.txt') || file_exists($theme_path . 'mails/' . $template . '.html')) {
$template_path = $theme_path . 'mails/';
$override_mail = true;
}
if (!file_exists($template_path . $template . '.txt') && ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT)) {
Tools::dieOrLog(Tools::displayError('Error - The following e-mail template is missing:') . ' ' . $template_path . $template . '.txt', $die);
return false;
} else {
if (!file_exists($template_path . $template . '.html') && ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML)) {
Tools::dieOrLog(Tools::displayError('Error - The following e-mail template is missing:') . ' ' . $template_path . $template . '.html', $die);
return false;
}
}
$template_html = file_get_contents($template_path . $template . '.html');
$template_txt = strip_tags(html_entity_decode(file_get_contents($template_path . $template . '.txt'), null, 'utf-8'));
if ($override_mail && file_exists($template_path . $iso . '/lang.php')) {
include_once $template_path . $iso . '/lang.php';
} else {
if ($module_name && file_exists($theme_path . 'mails/' . $iso . '/lang.php')) {
include_once $theme_path . 'mails/' . $iso . '/lang.php';
} else {
include_once _PS_MAIL_DIR_ . $iso . '/lang.php';
}
}
/* Create mail and attach differents parts */
$message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME', null, null, $id_shop) . '] ' . $subject);
/* Set Message-ID - getmypid() is blocked on some hosting */
$message->setId(Mail::generateId());
$message->headers->setEncoding('Q');
if (Configuration::get('PS_LOGO_MAIL') !== false && file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO_MAIL', null, null, $id_shop))) {
$logo = _PS_IMG_DIR_ . Configuration::get('PS_LOGO_MAIL', null, null, $id_shop);
} else {
if (file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO', null, null, $id_shop))) {
$logo = _PS_IMG_DIR_ . Configuration::get('PS_LOGO', null, null, $id_shop);
} else {
$template_vars['{shop_logo}'] = '';
}
}
/* don't attach the logo as */
if (isset($logo)) {
$template_vars['{shop_logo}'] = $message->attach(new Swift_Message_EmbeddedFile(new Swift_File($logo), null, ImageManager::getMimeTypeByExtension($logo)));
}
$template_vars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME', null, null, $id_shop));
$template_vars['{shop_url}'] = Tools::getShopDomain(true, true) . __PS_BASE_URI__ . 'index.php';
$template_vars['{my_account_url}'] = Context::getContext()->link->getPageLink('my-account', true, Context::getContext()->language->id);
$template_vars['{guest_tracking_url}'] = Context::getContext()->link->getPageLink('guest-tracking', true, Context::getContext()->language->id);
$template_vars['{history_url}'] = Context::getContext()->link->getPageLink('history', true, Context::getContext()->language->id);
$template_vars['{color}'] = Tools::safeOutput(Configuration::get('PS_MAIL_COLOR', null, null, $id_shop));
$swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $template_vars)), 'decorator');
if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT) {
$message->attach(new Swift_Message_Part($template_txt, 'text/plain', '8bit', 'utf-8'));
}
if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML) {
$message->attach(new Swift_Message_Part($template_html, 'text/html', '8bit', 'utf-8'));
}
if ($file_attachment && !empty($file_attachment)) {
// Multiple attachments?
if (!is_array(current($file_attachment))) {
$file_attachment = array($file_attachment);
}
foreach ($file_attachment as $attachment) {
if (isset($attachment['content']) && isset($attachment['name']) && isset($attachment['mime'])) {
$message->attach(new Swift_Message_Attachment($attachment['content'], $attachment['name'], $attachment['mime']));
}
}
}
/* Send mail */
$send = $swift->send($message, $to, new Swift_Address($from, $from_name));
$swift->disconnect();
return $send;
} catch (Swift_Exception $e) {
return false;
}
}
示例4: Send
//.........这里部分代码省略.........
$to_list->addTo($addr, '=?UTF-8?B?' . base64_encode($to_name) . '?=');
}
$to_plugin = $to[0];
$to = $to_list;
} else {
/* Simple recipient, one address */
$to_plugin = $to;
if ($toName == null) {
$toName = $to;
}
/* Encode accentuated chars */
$to = new Swift_Address($to, '=?UTF-8?B?' . base64_encode($toName) . '?=');
}
try {
/* Connect with the appropriate configuration */
if ($configuration['PS_MAIL_METHOD'] == 2) {
if (empty($configuration['PS_MAIL_SERVER']) || empty($configuration['PS_MAIL_SMTP_PORT'])) {
Tools::dieOrLog(Tools::displayError('Error: invalid SMTP server or SMTP port'), $die);
return false;
}
$connection = new Swift_Connection_SMTP($configuration['PS_MAIL_SERVER'], $configuration['PS_MAIL_SMTP_PORT'], $configuration['PS_MAIL_SMTP_ENCRYPTION'] == 'ssl' ? Swift_Connection_SMTP::ENC_SSL : ($configuration['PS_MAIL_SMTP_ENCRYPTION'] == 'tls' ? Swift_Connection_SMTP::ENC_TLS : Swift_Connection_SMTP::ENC_OFF));
$connection->setTimeout(20);
if (!$connection) {
return false;
}
if (!empty($configuration['PS_MAIL_USER'])) {
$connection->setUsername($configuration['PS_MAIL_USER']);
}
if (!empty($configuration['PS_MAIL_PASSWD'])) {
$connection->setPassword($configuration['PS_MAIL_PASSWD']);
}
} else {
$connection = new Swift_Connection_NativeMail();
}
if (!$connection) {
return false;
}
$swift = new Swift($connection, Configuration::get('PS_MAIL_DOMAIN'));
/* Get templates content */
$iso = Language::getIsoById((int) $id_lang);
if (!$iso) {
Tools::dieOrLog(Tools::displayError('Error - No ISO code for email'), $die);
return false;
}
$template = $iso . '/' . $template;
$moduleName = false;
$overrideMail = false;
// get templatePath
if (preg_match('#' . __PS_BASE_URI__ . 'modules/#', $templatePath) && preg_match('#modules/([a-z0-9_-]+)/#ui', $templatePath, $res)) {
$moduleName = $res[1];
}
if ($moduleName !== false && (file_exists(_PS_THEME_DIR_ . 'modules/' . $moduleName . '/mails/' . $template . '.txt') || file_exists(_PS_THEME_DIR_ . 'modules/' . $moduleName . '/mails/' . $template . '.html'))) {
$templatePath = _PS_THEME_DIR_ . 'modules/' . $moduleName . '/mails/';
} elseif (file_exists(_PS_THEME_DIR_ . 'mails/' . $template . '.txt') || file_exists(_PS_THEME_DIR_ . 'mails/' . $template . '.html')) {
$templatePath = _PS_THEME_DIR_ . 'mails/';
$overrideMail = true;
} elseif (!file_exists($templatePath . $template . '.html')) {
Tools::dieOrLog(Tools::displayError('Error - The following email template is missing:') . ' ' . $templatePath . $template . '.html', $die);
return false;
} elseif (!file_exists($templatePath . $template . '.txt')) {
Tools::dieOrLog(Tools::displayError('Error - The following email template is missing:') . ' ' . $templatePath . $template . '.txt', $die);
return false;
}
$templateHtml = file_get_contents($templatePath . $template . '.html');
$templateTxt = strip_tags(html_entity_decode(file_get_contents($templatePath . $template . '.txt'), null, 'utf-8'));
if ($overrideMail && file_exists($templatePath . $iso . '/lang.php')) {
include_once $templatePath . $iso . '/lang.php';
} else {
if ($moduleName && file_exists($templatePath . $iso . '/lang.php')) {
include_once _PS_THEME_DIR_ . 'mails/' . $iso . '/lang.php';
} else {
include_once dirname(__FILE__) . '/../mails/' . $iso . '/lang.php';
}
}
/* Create mail && attach differents parts */
$message = new Swift_Message('[' . Configuration::get('PS_SHOP_NAME') . '] ' . $subject);
/* Set Message-ID - getmypid() is blocked on some hosting */
$message->setId(Mail::generateId());
$message->headers->setEncoding('Q');
$templateVars['{shop_logo}'] = file_exists(_PS_IMG_DIR_ . 'logo_mail.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . 'logo_mail.jpg'))) : (file_exists(_PS_IMG_DIR_ . 'logo.jpg') ? $message->attach(new Swift_Message_Image(new Swift_File(_PS_IMG_DIR_ . 'logo.jpg'))) : '');
$templateVars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME'));
$templateVars['{shop_url}'] = Tools::getShopDomain(true, true) . __PS_BASE_URI__;
$swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $templateVars)), 'decorator');
if ($configuration['PS_MAIL_TYPE'] == 3 || $configuration['PS_MAIL_TYPE'] == 2) {
$message->attach(new Swift_Message_Part($templateTxt, 'text/plain', '8bit', 'utf-8'));
}
if ($configuration['PS_MAIL_TYPE'] == 3 || $configuration['PS_MAIL_TYPE'] == 1) {
$message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8'));
}
if ($fileAttachment && isset($fileAttachment['content']) && isset($fileAttachment['name']) && isset($fileAttachment['mime'])) {
$message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
}
/* Send mail */
$send = $swift->send($message, $to, new Swift_Address($from, $fromName));
$swift->disconnect();
return $send;
} catch (Swift_Exception $e) {
return false;
}
}