在codeigniter的helper用phpmailer 发送邮件_PHP教程
[php]
function send_mail($to,$title,$body)
{
$ci =& get_instance();
require_once('phpmailer/class.phpmailer.php');
require_once('phpmailer/class.smtp.php');
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->Host = $ci->config->item('mail_smtp'); // SMTP server
$mail->SMTPDebug = false; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = $ci->config->item('mail_port'); // set the SMTP port for the GMAIL server
$mail->Username = $ci->config->item('mail_address'); // SMTP account username
$mail->Password = $ci->config->item('mail_passwd'); // SMTP account password
$mail->AddAddress(www.2cto.com, '');
$mail->SetFrom($ci->config->item('mail_address'), $ci->config->item('mail_name'));
$mail->Subject = $title;
$mail->MsgHTML($body);
$mail->Send();
return true;
} catch (phpmailerException $e) {
//echo $e->errorMessage(); //Pretty error messages from PHPMailer
return false;
} catch (Exception $e) {
//echo $e->getMessage(); //Boring error messages from anything else!
return false;
}
}
function send_mail($to,$title,$body)
{
$ci =& get_instance();
require_once('phpmailer/class.phpmailer.php');
require_once('phpmailer/class.smtp.php');
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try {
$mail->Host = $ci->config->item('mail_smtp'); // SMTP server
$mail->SMTPDebug = false; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = $ci->config->item('mail_port'); // set the SMTP port for the GMAIL server
$mail->Username = $ci->config->item('mail_address'); // SMTP account username
$mail->Password = $ci->config->item('mail_passwd'); // SMTP account password
$mail->AddAddress(www.2cto.com, '');
$mail->SetFrom($ci->config->item('mail_address'), $ci->config->item('mail_name'));
$mail->Subject = $title;
$mail->MsgHTML($body);
$mail->Send();
return true;
} catch (phpmailerException $e) {
//echo $e->errorMessage(); //Pretty error messages from PHPMailer
return false;
} catch (Exception $e) {
//echo $e->getMessage(); //Boring error messages from anything else!
return false;
}
}
另外在config里写入你的邮箱配置项
[php]
$config['mail_name']='焦常云';
$config['mail_passwd']='password';
$config['mail_address']='xxxx@21cn.com';
$config['mail_smtp']='smtp.21cn.com';
$config['mail_smtp_port']=25;
$config['mail_name']='焦常云';
$config['mail_passwd']='password';
$config['mail_address']='xxxx@21cn.com';
$config['mail_smtp']='smtp.21cn.com';
$config['mail_smtp_port']=25;
作者:jiaochangyun
推荐阅读
-
在codeigniter的helper用phpmailer 发送邮件_PHP教程
-
Codeigniter实现发送带附件的邮件,codeigniter附件_PHP教程
-
163的邮件用phpmailer发送(实例详解)_PHP教程
-
解析yahoo邮件用phpmailer发送的实例_PHP教程
-
解析php中用PHPMailer来发送邮件的示例(126.com的例子)_PHP教程
-
phpmailer在服务器上不能正常发送邮件的解决办法_PHP
-
phpmailer简单发送邮件的方法(附phpmailer源码下载),phpmailer源码下载_PHP教程
-
phpmailer在服务器上不能正常发送邮件的解决办法_PHP
-
PHPMailer使用Gmail来发送邮件的连接smtp服务器错误_PHP教程
-
php 用sock技术发送邮件的函数_PHP教程