phpmailerはメールを送信します(強いですねほほほ)
2666 ワード
私は简単にカプセル化しました:ダウンロードのアドレスはネット上で検索することができて、検索できないmailは私にあげることができます
テストの例
<?php
require_once dirname(__FILE__)."/PHPMailer_5.2.1/class.phpmailer.php";
include dirname(__FILE__)."/PHPMailer_5.2.1/class.smtp.php";
class Mail{
public function postMail($to,$subject,$body){
$mail = new PHPMailer(); //new PHPMailer
$body = eregi_replace("[\]",'',$body); //
$mail->CharSet ="UTF-8";// , ISO-8859-1, ,
$mail->IsSMTP(); // SMTP
$mail->SMTPDebug = 1; // SMTP
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // SMTP
$mail->SMTPSecure = "ssl"; //
$mail->Host = "xxxxxxxxxxxxxx"; // SMTP
$mail->Port = xxxxx; // SMTP
$mail->Username = "xxxxxxxxxxxx"; // SMTP
$mail->Password = "xxxxxxx"; // SMTP
$mail->SetFrom('[email protected]', 'xxxxxxxxx');
$mail->AddReplyTo("[email protected]","xxxxxxx");
$mail->Subject = $subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer! - From www.xxxxxxxxx.com"; // optional, comment out and test
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, "xxxxxxx");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
// header("Content-Type:text/html;charset=utf-8");
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
// header("Content-Type:text/html;charset=utf-8");
echo "Message sent! , !";
}
}
}
?>
テストの例
<?php
require_once dirname(__FILE__).'/lib/mail.php';
$obj = new Mail();
$content = <<<EOT
<html>
<head></head>
<body>
<table style="background-color:#eee;background-image:url('http://index.youku.com/index/img/logo/logo_vr.png');border:1px solid #999">
<th>
<td>This is a email</td>
</th>
<tr>
<td>Yes</td>
</tr>
</table>
</body>
</html>
EOT;
$obj->postMail('[email protected]','Important File',$content);