使用PHPMailer发送邮件
(导包class.phpmailer.php,class.smtp.php)
1.在邮箱设置 账户里设置POP3/SMTP开启,将自己的qq邮箱作为发送方;
<?php
function mail($from_email,$to_email,$cc_email,$mail_subject,$mail_content)
{
$mail = new PHPMailer();
try {
$mail->IsSMTP();
// $mail->Host = "10.105.15.21";// smtp服务器地址
$mail->Host = "smtp.qq.com";
$mail->SMTPAuth = true;
$mail->Username = "xx@qq.com";
$mail->Password = '输入qq邮箱密码';
$mail->From = xx@qq.com';$mail->Port = 25;//端口
//$mail->From = 'itsys@xx.com';// 发件人邮箱
$mail->FromName = "DPSK-IT"; // 发件人
$mail->WordWrap = 50;
$mail->AddAttachment("");
$mail->IsHTML(true);
$mail->Subject = $mail_subject;
$mail->Body = $mail_content;
$emails = explode(',',$to_email);
$cc_emails = explode(',',$cc_email);
foreach ($emails as $key)
{
$mail->AddAddress($key);
}
foreach ($cc_emails as $key)
{
if (!empty($key))
$mail->AddCC($key);
}
if(!$mail->Send())
{
echo 'Mailer Error: ' . $mail->ErrorInfo;
return false;
} else {
// return true;
echo '邮件发送成功!请注意接收!';
}
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
}
2.直接使用公司邮箱
<?php
function jingcemail($from_email,$to_email,$cc_email,$mail_subject,$mail_content)
{
$mail = new PHPMailer();
try {
$mail->IsSMTP();
$mail->Host = "10.105.15.21";// smtp服务器地址
// $mail->Host = "smtp.qq.com";
$mail->SMTPAuth = true;
// $mail->Username = "fdf@qq.com";
// $mail->Password = 'jdfdf';
//$mail->From = xx@qq.com';$mail->Port = 25;//端口
$mail->From = 'itsys@xx.com';// 发件人邮箱
$mail->FromName = "DPSK-IT"; // 发件人
$mail->WordWrap = 50;
$mail->AddAttachment("");
$mail->IsHTML(true);
$mail->Subject = $mail_subject;
$mail->Body = $mail_content;
$emails = explode(',',$to_email);
$cc_emails = explode(',',$cc_email);
foreach ($emails as $key)
{
$mail->AddAddress($key);
}
foreach ($cc_emails as $key)
{
if (!empty($key))
$mail->AddCC($key);
}
if(!$mail->Send())
{
echo 'Mailer Error: ' . $mail->ErrorInfo;
return false;
} else {
// return true;
echo '邮件发送成功!请注意查收!';
}
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
}