本文整理匯總了PHP中smtp::error_msg方法的典型用法代碼示例。如果您正苦於以下問題:PHP smtp::error_msg方法的具體用法?PHP smtp::error_msg怎麽用?PHP smtp::error_msg使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類smtp
的用法示例。
在下文中一共展示了smtp::error_msg方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: send_mail
//.........這裏部分代碼省略.........
{
return true;
}
}
/**
* 使用smtp服務發送郵件
*/
else
{
/* 郵件的頭部信息 */
$content_type = ($type == 0) ?
'Content-Type: text/plain; charset=' . $charset : 'Content-Type: text/html; charset=' . $charset;
$content = base64_encode($content);
$headers = array();
$headers[] = 'Date: ' . gmdate('D, j M Y H:i:s') . ' +0000';
$headers[] = 'To: "' . '=?' . $charset . '?B?' . base64_encode($name) . '?=' . '" <' . $email. '>';
$headers[] = 'From: "' . '=?' . $charset . '?B?' . base64_encode($shop_name) . '?='.'" <' . $GLOBALS['_CFG']['smtp_mail'] . '>';
$headers[] = 'Subject: ' . '=?' . $charset . '?B?' . base64_encode($subject) . '?=';
$headers[] = $content_type . '; format=flowed';
$headers[] = 'Content-Transfer-Encoding: base64';
$headers[] = 'Content-Disposition: inline';
if ($notification)
{
$headers[] = 'Disposition-Notification-To: ' . '=?' . $charset . '?B?' . base64_encode($shop_name) . '?='.'" <' . $GLOBALS['_CFG']['smtp_mail'] . '>';
}
/* 獲得郵件服務器的參數設置 */
$params['host'] = $GLOBALS['_CFG']['smtp_host'];
$params['port'] = $GLOBALS['_CFG']['smtp_port'];
$params['user'] = $GLOBALS['_CFG']['smtp_user'];
$params['pass'] = $GLOBALS['_CFG']['smtp_pass'];
if (empty($params['host']) || empty($params['port']))
{
// 如果沒有設置主機和端口直接返回 false
$GLOBALS['err'] ->add($GLOBALS['_LANG']['smtp_setting_error']);
return false;
}
else
{
// 發送郵件
if (!function_exists('fsockopen'))
{
//如果fsockopen被禁用,直接返回
$GLOBALS['err']->add($GLOBALS['_LANG']['disabled_fsockopen']);
return false;
}
include_once(ROOT_PATH . 'includes/cls_smtp.php');
static $smtp;
$send_params['recipients'] = $email;
$send_params['headers'] = $headers;
$send_params['from'] = $GLOBALS['_CFG']['smtp_mail'];
$send_params['body'] = $content;
if (!isset($smtp))
{
$smtp = new smtp($params);
}
if ($smtp->connect() && $smtp->send($send_params))
{
return true;
}
else
{
$err_msg = $smtp->error_msg();
if (empty($err_msg))
{
$GLOBALS['err']->add('Unknown Error');
}
else
{
if (strpos($err_msg, 'Failed to connect to server') !== false)
{
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['smtp_connect_failure'], $params['host'] . ':' . $params['port']));
}
else if (strpos($err_msg, 'AUTH command failed') !== false)
{
$GLOBALS['err']->add($GLOBALS['_LANG']['smtp_login_failure']);
}
elseif (strpos($err_msg, 'bad sequence of commands') !== false)
{
$GLOBALS['err']->add($GLOBALS['_LANG']['smtp_refuse']);
}
else
{
$GLOBALS['err']->add($err_msg);
}
}
return false;
}
}
}
}
示例2: send_mail
/**
* Óʼþ·¢ËÍ.
*
* @param: $name[string] ½ÓÊÕÈËÐÕÃû
* @param: $email[string] ½ÓÊÕÈËÓʼþµØÖ·
* @param: $subject[string] Óʼþ±êÌâ
* @param: $content[string] ÓʼþÄÚÈÝ
* @param: $type[int] 0 ÆÕͨÓʼþ£¬ 1 HTMLÓʼþ
* @param: $notification[bool] true ÒªÇó»ØÖ´£¬ false ²»ÓûØÖ´
*
* @return bool
*/
function send_mail($name, $email, $subject, $content, $type = 0, $notification = false)
{
/* Èç¹ûÓʼþ±àÂë²»ÊÇEC_CHARSET£¬´´½¨×Ö·û¼¯×ª»»¶ÔÏó£¬×ª»»±àÂë */
if ($GLOBALS['_CFG']['mail_charset'] != EC_CHARSET) {
$name = ecs_iconv(EC_CHARSET, $GLOBALS['_CFG']['mail_charset'], $name);
$subject = ecs_iconv(EC_CHARSET, $GLOBALS['_CFG']['mail_charset'], $subject);
$content = ecs_iconv(EC_CHARSET, $GLOBALS['_CFG']['mail_charset'], $content);
$shop_name = ecs_iconv(EC_CHARSET, $GLOBALS['_CFG']['mail_charset'], $GLOBALS['_CFG']['shop_name']);
}
$charset = $GLOBALS['_CFG']['mail_charset'];
/*
* ʹÓÃmailº¯Êý·¢ËÍÓʼþ
*/
if ($GLOBALS['_CFG']['mail_service'] == 0 && function_exists('mail')) {
/* ÓʼþµÄÍ·²¿ÐÅÏ¢ */
$content_type = $type == 0 ? 'Content-Type: text/plain; charset=' . $charset : 'Content-Type: text/html; charset=' . $charset;
$headers = array();
$headers[] = 'From: "' . '=?' . $charset . '?B?' . base64_encode($shop_name) . '?=' . '" <' . $GLOBALS['_CFG']['smtp_mail'] . '>';
$headers[] = $content_type . '; format=flowed';
if ($notification) {
$headers[] = 'Disposition-Notification-To: ' . '=?' . $charset . '?B?' . base64_encode($shop_name) . '?=' . '" <' . $GLOBALS['_CFG']['smtp_mail'] . '>';
}
$res = @mail($email, '=?' . $charset . '?B?' . base64_encode($subject) . '?=', $content, implode("\r\n", $headers));
if (!$res) {
$GLOBALS['err']->add($GLOBALS['_LANG']['sendemail_false']);
return false;
} else {
return true;
}
} else {
/* ÓʼþµÄÍ·²¿ÐÅÏ¢ */
$content_type = $type == 0 ? 'Content-Type: text/plain; charset=' . $charset : 'Content-Type: text/html; charset=' . $charset;
$content = base64_encode($content);
$headers = array();
$headers[] = 'Date: ' . gmdate('D, j M Y H:i:s') . ' +0000';
$headers[] = 'To: "' . '=?' . $charset . '?B?' . base64_encode($name) . '?=' . '" <' . $email . '>';
$headers[] = 'From: "' . '=?' . $charset . '?B?' . base64_encode($shop_name) . '?=' . '" <' . $GLOBALS['_CFG']['smtp_mail'] . '>';
$headers[] = 'Subject: ' . '=?' . $charset . '?B?' . base64_encode($subject) . '?=';
$headers[] = $content_type . '; format=flowed';
$headers[] = 'Content-Transfer-Encoding: base64';
$headers[] = 'Content-Disposition: inline';
if ($notification) {
$headers[] = 'Disposition-Notification-To: ' . '=?' . $charset . '?B?' . base64_encode($shop_name) . '?=' . '" <' . $GLOBALS['_CFG']['smtp_mail'] . '>';
}
/* »ñµÃÓʼþ·þÎñÆ÷µÄ²ÎÊýÉèÖà */
$params['host'] = $GLOBALS['_CFG']['smtp_host'];
$params['port'] = $GLOBALS['_CFG']['smtp_port'];
$params['user'] = $GLOBALS['_CFG']['smtp_user'];
$params['pass'] = $GLOBALS['_CFG']['smtp_pass'];
if (empty($params['host']) || empty($params['port'])) {
// Èç¹ûûÓÐÉèÖÃÖ÷»úºÍ¶Ë¿ÚÖ±½Ó·µ»Ø false
$GLOBALS['err']->add($GLOBALS['_LANG']['smtp_setting_error']);
return false;
} else {
// ·¢ËÍÓʼþ
if (!function_exists('fsockopen')) {
//Èç¹ûfsockopen±»½ûÓã¬Ö±½Ó·µ»Ø
$GLOBALS['err']->add($GLOBALS['_LANG']['disabled_fsockopen']);
return false;
}
include_once ROOT_PATH . 'includes/cls_smtp.php';
static $smtp;
$send_params['recipients'] = $email;
$send_params['headers'] = $headers;
$send_params['from'] = $GLOBALS['_CFG']['smtp_mail'];
$send_params['body'] = $content;
if (!isset($smtp)) {
$smtp = new smtp($params);
}
if ($smtp->connect() && $smtp->send($send_params)) {
return true;
} else {
$err_msg = $smtp->error_msg();
if (empty($err_msg)) {
$GLOBALS['err']->add('Unknown Error');
} else {
if (strpos($err_msg, 'Failed to connect to server') !== false) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['smtp_connect_failure'], $params['host'] . ':' . $params['port']));
} elseif (strpos($err_msg, 'AUTH command failed') !== false) {
$GLOBALS['err']->add($GLOBALS['_LANG']['smtp_login_failure']);
} elseif (strpos($err_msg, 'bad sequence of commands') !== false) {
$GLOBALS['err']->add($GLOBALS['_LANG']['smtp_refuse']);
} else {
$GLOBALS['err']->add($err_msg);
}
}
return false;
}
//.........這裏部分代碼省略.........