laravel - 邮件发送网页形式
发送邮件,以网页的形式,图片手动更改为base64,邮件发送使用PHPMailer
//html mail.blade.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.mailview {
width: 650px;
text-align: center;
}
h1 {
padding-top: 110px;
font-size: 40px;
}
.p1 {
padding-bottom: 40px;
font-weight: bold;
font-size: 16px;
}
hr {
color: #f0f2f4;
width: 80%;
}
.p2 {
padding-top: 40px;
font-size: 14px;
}
.p3 {
font-size: 14px;
}
.p4 {
padding-top: 80px;
padding-bottom: 60px;
}
a {
display: inline-block;
padding: 10px 28px;
font-size: 12px;
font-weight: bold;
text-align: center;
text-decoration: none;
color: #000;
border: 2px solid #000;
transition: all .2s linear;
}
a:hover {
background: #df0036;
color: #FFFFFF;
border-color: #df0036;
}
</style>
</head>
<body>
<div class="mailview">
<div class="container">
<img src="data:image/png;base64,shshshshshhs"alt="">
<h1>
收到咨询
</h1>
<div class="p1">
您咨询的问题已收到。
</div>
<hr>
<div class="p2">
我们会尽快回复您的问题。
</div>
<div class="p3">
谢谢。
</div>
<div class="p4">
<a href=""> 官网</a>
</div>
<img src="data:image/png;base64,bshshshshshsh"alt="">
</div>
</div>
</body>
</html>
//controller
$emails = ['sssss@qq.com','wwwwww@123.com' ];
$view1 = View::make('test/mail');
$html1 = $view1->__toString();
$this->sendMail($emails, '咨询用户', '来自客户的咨询', $html1);
/**
* +---------------------------------------
* 发送邮件
* +---------------------------------------
*/
public function sendMail($address, $name, $subject, $body)
{
$mail = new PHPMailer(true);
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'sss'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'sss'; // SMTP username
$mail->Password = 'sss'; // SMTP password
$mail->SMTPSecure = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
); // Enable TLS encryption, `ssl` also accepted
//设置ssl连接smtp服务器的远程服务器端口号,以前的默认是25,但是现在新的好像已经不可用了 可选465或587
$mail->Port = 587;
$mail->setFrom('sdas', '官网');
// $mail->addCC('sda@das.com');
//多人发送
foreach ($address as $item) {
$mail->addAddress($item, $name); // Add a recipient
}
// $mail->addAddress($address, $name);
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->CharSet = "utf-8"; // 这里指定字符集
$mail->Encoding = "base64";
$mail->Subject = $subject;
$mail->Body = $body;
$mail->SingleTo = true; //将邮件分发到每个电子邮件地址
$send = $mail->send();
if (!$send) {
$return = false;
} else {
$return = true;
}
$mail->clearAddresses();
$mail->clearAttachments();
return $return;
}