本文整理汇总了PHP中Swift::setCharset方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift::setCharset方法的具体用法?PHP Swift::setCharset怎么用?PHP Swift::setCharset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift
的用法示例。
在下文中一共展示了Swift::setCharset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMailer
/**
* This function will return SMTP connection. It will try to load options from
* config and if it fails it will use settings from php.ini
*
* @param void
* @return Swift
*/
static function getMailer()
{
$mail_transport_config = config_option('mail_transport', self::MAIL_TRANSPORT_MAIL);
// Emulate mail() - use NativeMail
if ($mail_transport_config == self::MAIL_TRANSPORT_MAIL) {
$mailer = new Swift(new Swift_Connection_NativeMail());
return $mailer->isConnected() ? $mailer : null;
// Use SMTP server
} elseif ($mail_transport_config == self::MAIL_TRANSPORT_SMTP) {
// Load SMTP config
$smtp_server = config_option('smtp_server');
$smtp_port = config_option('smtp_port', 25);
$smtp_secure_connection = config_option('smtp_secure_connection', self::SMTP_SECURE_CONNECTION_NO);
$smtp_authenticate = config_option('smtp_authenticate', false);
if ($smtp_authenticate) {
$smtp_username = config_option('smtp_username');
$smtp_password = config_option('smtp_password');
}
// if
switch ($smtp_secure_connection) {
case self::SMTP_SECURE_CONNECTION_SSL:
$transport = SWIFT_SSL;
break;
case self::SMTP_SECURE_CONNECTION_TLS:
$transport = SWIFT_TLS;
break;
default:
$transport = SWIFT_OPEN;
}
// switch
$mailer = new Swift(new Swift_Connection_SMTP($smtp_server, $smtp_port, $transport));
if (!$mailer->isConnected()) {
return null;
}
// if
$mailer->setCharset('UTF-8');
if ($smtp_authenticate) {
if ($mailer->authenticate($smtp_username, $smtp_password)) {
return $mailer;
} else {
return null;
}
// if
} else {
return $mailer;
}
// if
// Somethings wrong here...
} else {
return null;
}
// if
}
示例2: getContent
function getContent($smtp_server, $smtp_port, $transport, $smtp_username, $smtp_password, $body, $attachments)
{
//Load in the files we'll need
Env::useLibrary('swift');
switch ($transport) {
case 'ssl':
$transport = SWIFT_SSL;
break;
case 'tls':
$transport = SWIFT_TLS;
break;
default:
$transport = 0;
break;
}
//Start Swift
$mailer = new Swift(new Swift_Connection_SMTP($smtp_server, $smtp_port, $transport));
if (!$mailer->isConnected()) {
return false;
}
// if
$mailer->setCharset('UTF-8');
if ($smtp_username != null) {
if (!$mailer->authenticate($smtp_username, self::ENCRYPT_DECRYPT($smtp_password))) {
return false;
}
}
if (!$mailer->isConnected()) {
return false;
}
// add attachments
$mailer->addPart($body);
// real body
if (is_array($attachments) && count($attachments) > 0) {
foreach ($attachments as $att) {
$mailer->addAttachment($att["data"], $att["name"], $att["type"]);
}
}
$content = $mailer->getFullContent(false);
$mailer->close();
return $content;
}