最近需要用到发送邮件的功能,原本是用PHP自带的mail()函数发送的。php mail()这个方法非常简单、方便、易用,但是除了网易邮箱、QQ邮箱、GMAIL邮箱等常用的邮箱可以收到之外,经测试HOTMAIL、TOM、LIVE等邮箱是收不到此类邮件的。所以就转而使用PHPMailer这个强大的邮件发送类。
使用官方自带的一些例子,有些会报 Mailer Error: Could not instantiate mail function. 这个错误。参考了一些资料之后,还是自己写了一个方法。代码很简单,就不多解释了。
function mailto($nickname, $address, $id, $activation_code)<BR>{<BR> date_default_timezone_set('PRC'); <BR> include_once("class.phpmailer.php");<br><br> $mail = new PHPMailer(); // defaults to using php "mail()"<BR> $mail->IsSMTP();<BR> $mail->Host = "smtp.163.com"; // SMTP 服务器 <BR> $mail->SMTPAuth = true; // 打开SMTP 认证 <BR> $mail->Username = "[email protected]"; // 用户名<BR> $mail->Password = "yourpassword"; // 密码 <br><br> //$body = file_get_contents('application/views/nmra/register.html');<BR> //$body = preg_replace('/\\\\/','', $body); //Strip backslashes<BR> $body = '<p><body style="margin: 10px;"></p>';<BR> $body .= '<div style="width: 640px;font-family: Arial, Helvetica, sans-serif;font-size: 14px">';<BR> $body .= '<div align="center">
‘;
$body .= ‘
‘.$nickname.’,您好。
‘;
$body .= ‘
恭喜你成为简明现代魔法研究协会的第’.$id.’名会员。
‘;
$body .= ‘
现代魔法研究协会(NowaMagic Research Association)是一个程序猿、攻城狮、设计狮和开发者们技术交流、话题讨论的社区。希望在这里你能找到感兴趣的话题与志同道合的朋友。
‘;
$body .= ‘请点击以下链接验证您的邮箱,请注意域名为nowamagic.net:http://www.nowamagic.net/librarys/accounts/activation/?code=’.$activation_code.”;
$body .= ‘
顺祝工作学习愉快,生活舒心。
‘;
$body .= ‘