php记录邮件发送,有关php邮件发送一点记录
php郵件發送需要準備2個文件:一個是?class.phpmailer.php',另一個是: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 = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username ='sgo@gmail.com'; // GMAIL username
$mail->Password = "123456"; // GMAIL password
$mail->AddReplyTo('sgo@gmail.com', 'test');
$mail->AddAddress($email, $username);//根據傳進來的郵件地址參數,發送郵件
$mail->SetFrom('sgo@gmail.com', 'test');
$mail->AddReplyTo('sgo@gmail.com', 'test');
//以上郵箱的配置,qq和gmail都測試過,不過新的qq郵箱會把郵件截住,老的qq郵箱還是挺順暢的。
$mail->Subject = 'Welcome!';
$mail->AltBody = 'Go!'; // optional - MsgHTML will create an alternate automatically
$body ="";
// 郵件的發送大概有2種方式:
一種是直接發送靜態頁面?$mail->MsgHTML(file_get_contents('contents.html'));//$mail->MsgHTML(file_get_contents('views/find.html'));這一種方式發送比較簡潔,不過很難向靜態頁面傳遞參數
另一種是構建body,這一種比較費時,但是容易傳參,一下就構建body的常用格式的一點記錄
$mail->Body="
//在郵件里構建圖片
"
系統自動發送了該郵件
"//一般的文字"
請點擊://a標簽的寫法,雙引號要轉義
body結束,下面是附件
$mail->AddEmbeddedImage('views/image/you_logo.png',"my-attach"); // 向剛才構建的圖片里嵌入一張圖片,my-attach是cid
//$mail->AddAttachment('images/phpmailer_mini.gif'); //加入附件,附件形式可以是圖片、聲音等等
//$mail->Send();郵件發送
//echo $mail->Send();
if($mail->Send()){
$this->redirect('/simple/send?email='.$email);
}else{
echo "mail test!!!";
}
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
}
總結
以上是生活随笔為你收集整理的php记录邮件发送,有关php邮件发送一点记录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php中一定要写 吗,PHP编程一定要改
- 下一篇: oracle中constraints,o