+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018 |
+ | Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
*/
class CRM_Utils_Mail {
if ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB ||
(defined('CIVICRM_MAILER_SPOOL') && CIVICRM_MAILER_SPOOL)
) {
- $mailer = self::_createMailer('CRM_Mailing_BAO_Spool', array());
+ $mailer = self::_createMailer('CRM_Mailing_BAO_Spool', []);
}
elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_SMTP) {
if ($mailingInfo['smtpServer'] == '' || !$mailingInfo['smtpServer']) {
- CRM_Core_Error::debug_log_message(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the SMTP Server.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
- CRM_Core_Error::fatal(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the SMTP Server.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
+ CRM_Core_Error::debug_log_message(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the SMTP Server.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
+ CRM_Core_Error::fatal(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the SMTP Server.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
}
$params['host'] = $mailingInfo['smtpServer'] ? $mailingInfo['smtpServer'] : 'localhost';
if ($mailingInfo['sendmail_path'] == '' ||
!$mailingInfo['sendmail_path']
) {
- CRM_Core_Error::debug_log_message(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the sendmail server.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
- CRM_Core_Error::fatal(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the sendmail server.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
+ CRM_Core_Error::debug_log_message(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the sendmail server.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
+ CRM_Core_Error::fatal(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the sendmail server.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
}
$params['sendmail_path'] = $mailingInfo['sendmail_path'];
$params['sendmail_args'] = $mailingInfo['sendmail_args'];
$mailer = self::_createMailer('sendmail', $params);
}
elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MAIL) {
- $mailer = self::_createMailer('mail', array());
+ $mailer = self::_createMailer('mail', []);
}
elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MOCK) {
- $mailer = self::_createMailer('mock', array());
+ $mailer = self::_createMailer('mock', []);
}
elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED) {
- CRM_Core_Error::debug_log_message(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
- CRM_Core_Error::statusBounce(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
+ CRM_Core_Error::debug_log_message(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
+ CRM_Core_Error::statusBounce(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
}
else {
- CRM_Core_Error::debug_log_message(ts('There is no valid SMTP server Setting Or SendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
+ CRM_Core_Error::debug_log_message(ts('There is no valid SMTP server Setting Or SendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
CRM_Core_Error::debug_var('mailing_info', $mailingInfo);
- CRM_Core_Error::statusBounce(ts('There is no valid SMTP server Setting Or sendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
+ CRM_Core_Error::statusBounce(ts('There is no valid SMTP server Setting Or sendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', [1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1')]));
}
return $mailer;
}
$htmlMessage = FALSE;
}
- $headers = array();
+ $headers = [];
// CRM-10699 support custom email headers
if (!empty($params['headers'])) {
$headers = array_merge($headers, $params['headers']);
}
// make sure we has to have space, CRM-6977
- foreach (array('From', 'To', 'Cc', 'Bcc', 'Reply-To', 'Return-Path') as $fld) {
+ foreach (['From', 'To', 'Cc', 'Bcc', 'Reply-To', 'Return-Path'] as $fld) {
if (isset($headers[$fld])) {
$headers[$fld] = str_replace('"<', '" <', $headers[$fld]);
}
$message = self::setMimeParams($msg);
$headers = $msg->headers($headers);
- $to = array($params['toEmail']);
+ $to = [$params['toEmail']];
$result = NULL;
$mailer = \Civi::service('pear_mail');
* @return string
*/
public static function errorMessage($mailer, $result) {
- $message = '<p>' . ts('An error occurred when CiviCRM attempted to send an email (via %1). If you received this error after submitting on online contribution or event registration - the transaction was completed, but we were unable to send the email receipt.', array(
- 1 => 'SMTP',
- )) . '</p>' . '<p>' . ts('The mail library returned the following error message:') . '<br /><span class="font-red"><strong>' . $result->getMessage() . '</strong></span></p>' . '<p>' . ts('This is probably related to a problem in your Outbound Email Settings (Administer CiviCRM » System Settings » Outbound Email), OR the FROM email address specifically configured for your contribution page or event. Possible causes are:') . '</p>';
+ $message = '<p>' . ts('An error occurred when CiviCRM attempted to send an email (via %1). If you received this error after submitting on online contribution or event registration - the transaction was completed, but we were unable to send the email receipt.', [
+ 1 => 'SMTP',
+ ]) . '</p>' . '<p>' . ts('The mail library returned the following error message:') . '<br /><span class="font-red"><strong>' . $result->getMessage() . '</strong></span></p>' . '<p>' . ts('This is probably related to a problem in your Outbound Email Settings (Administer CiviCRM » System Settings » Outbound Email), OR the FROM email address specifically configured for your contribution page or event. Possible causes are:') . '</p>';
if (is_a($mailer, 'Mail_smtp')) {
$message .= '<ul>' . '<li>' . ts('Your SMTP Username or Password are incorrect.') . '</li>' . '<li>' . ts('Your SMTP Server (machine) name is incorrect.') . '</li>' . '<li>' . ts('You need to use a Port other than the default port 25 in your environment.') . '</li>' . '<li>' . ts('Your SMTP server is just not responding right now (it is down for some reason).') . '</li>';
$message .= '<ul>' . '<li>' . ts('Your Sendmail path is incorrect.') . '</li>' . '<li>' . ts('Your Sendmail argument is incorrect.') . '</li>';
}
- $message .= '<li>' . ts('The FROM Email Address configured for this feature may not be a valid sender based on your email service provider rules.') . '</li>' . '</ul>' . '<p>' . ts('Check <a href="%1">this page</a> for more information.', array(
- 1 => CRM_Utils_System::docURL2('user/advanced-configuration/email-system-configuration', TRUE),
- )) . '</p>';
+ $message .= '<li>' . ts('The FROM Email Address configured for this feature may not be a valid sender based on your email service provider rules.') . '</li>' . '</ul>' . '<p>' . ts('Check <a href="%1">this page</a> for more information.', [
+ 1 => CRM_Utils_System::docURL2('user/advanced-configuration/email-system-configuration', TRUE),
+ ]) . '</p>';
return $message;
}
static $mimeParams = NULL;
if (!$params) {
if (!$mimeParams) {
- $mimeParams = array(
+ $mimeParams = [
'text_encoding' => '8bit',
'html_encoding' => '8bit',
'head_charset' => 'utf-8',
'text_charset' => 'utf-8',
'html_charset' => 'utf-8',
- );
+ ];
}
$params = $mimeParams;
}
if (!empty($name)) {
// escape the special characters
- $name = str_replace(array('<', '"', '>'),
- array('\<', '\"', '\>'),
+ $name = str_replace(['<', '"', '>'],
+ ['\<', '\"', '\>'],
$name
);
if (strpos($name, ',') !== FALSE ||
TRUE,
$format)
);
- return array(
+ return [
'fullPath' => $pdf_filename,
'mime_type' => 'application/pdf',
'cleanName' => $fileName,
- );
+ ];
}
/**
$formattedEmail = $fields['email'];
}
- $formattedSuffix = array();
+ $formattedSuffix = [];
if (!empty($fields['is_bulkmail'])) {
$formattedSuffix[] = '(' . ts('Bulk') . ')';
}
return $formattedEmail;
}
+ /**
+ * When passed a value, returns the value if it's non-numeric.
+ * If it's numeric, look up the display name and email of the corresponding
+ * contact ID in RFC822 format.
+ *
+ * @param string $from
+ * contact ID or formatted "From address", eg. 12 or "Fred Bloggs" <fred@example.org>
+ * @return string
+ * The RFC822-formatted email header (display name + address)
+ */
+ public static function formatFromAddress($from) {
+ if (is_numeric($from)) {
+ $result = civicrm_api3('Email', 'get', [
+ 'id' => $from,
+ 'return' => ['contact_id.display_name', 'email'],
+ 'sequential' => 1,
+ ])['values'][0];
+ $from = '"' . $result['contact_id.display_name'] . '" <' . $result['email'] . '>';
+ }
+ return $from;
+ }
+
}