如何使用bootstrap-4以自定义设计在电子邮件正文中发送消息?
我正在尝试使用CodeIgniter-4框架通过smtp发送消息。为此,我使用bootstrap-4设计了一个卡作为消息体,并希望将此消息发送给接收方。我可以成功发送此邮件,但邮件在设计时不可见。Bootstrap-4类不工作 我想如何显示接收者:如何使用bootstrap-4以自定义设计在电子邮件正文中发送消息?,bootstrap-4,smtp,email-attachments,codeigniter-4,Bootstrap 4,Smtp,Email Attachments,Codeigniter 4,我正在尝试使用CodeIgniter-4框架通过smtp发送消息。为此,我使用bootstrap-4设计了一个卡作为消息体,并希望将此消息发送给接收方。我可以成功发送此邮件,但邮件在设计时不可见。Bootstrap-4类不工作 我想如何显示接收者: namespace Config; use CodeIgniter\Config\BaseConfig; class Email extends BaseConfig { /** * @var string */ public $fromE
namespace Config;
use CodeIgniter\Config\BaseConfig;
class Email extends BaseConfig
{
/**
* @var string
*/
public $fromEmail;
/**
* @var string
*/
public $fromName;
/**
* @var string
*/
public $recipients;
/**
* The "user agent"
*
* @var string
*/
public $userAgent = 'CodeIgniter';
/**
* The mail sending protocol: mail, sendmail, smtp
*
* @var string
*/
public $protocol = 'smtp';
/**
* The server path to Sendmail.
*
* @var string
*/
public $mailPath = '/usr/sbin/sendmail';
/**
* SMTP Server Address
*
* @var string
*/
public $SMTPHost = 'smtp.office365.com';
/**
* SMTP Username
*
* @var string
*/
// Enter your email id from where you send email
public $SMTPUser = 'exampleMail@gmail.com';
/**
* SMTP Password
*
* @var string
*/
// Enter your email's password
public $SMTPPass = 'myPassword';
/**
* SMTP Port
*
* @var integer
*/
public $SMTPPort = 587;
/**
* SMTP Timeout (in seconds)
*
* @var integer
*/
public $SMTPTimeout = 60;
/**
* Enable persistent SMTP connections
*
* @var boolean
*/
public $SMTPKeepAlive = false;
/**
* SMTP Encryption. Either tls or ssl
*
* @var string
*/
public $SMTPCrypto = 'tls';
/**
* Enable word-wrap
*
* @var boolean
*/
public $wordWrap = true;
/**
* Character count to wrap at
*
* @var integer
*/
public $wrapChars = 76;
/**
* Type of mail, either 'text' or 'html'
*
* @var string
*/
public $mailType = 'html';
/**
* Character set (utf-8, iso-8859-1, etc.)
*
* @var string
*/
public $charset = 'UTF-8';
/**
* Whether to validate the email address
*
* @var boolean
*/
public $validate = false;
/**
* Email Priority. 1 = highest. 5 = lowest. 3 = normal
*
* @var integer
*/
public $priority = 3;
/**
* Newline character. (Use “\r\n” to comply with RFC 822)
*
* @var string
*/
public $CRLF = "\r\n";
/**
* Newline character. (Use “\r\n” to comply with RFC 822)
*
* @var string
*/
public $newline = "\r\n";
/**
* Enable BCC Batch Mode.
*
* @var boolean
*/
public $BCCBatchMode = false;
/**
* Number of emails in each BCC batch
*
* @var integer
*/
public $BCCBatchSize = 200;
/**
* Enable notify message from server
*
* @var boolean
*/
public $DSN = false;
}
namespace App\Controllers;
use App\Models\FormModel;
use CodeIgniter\Controller;
class SendMail extends Controller
{
function check() {
$data['title']="Mail";
echo view('template/header.php',$data);
$to = 'exampleMail@gmail.com';
$subject = 'Vehicle Management System';
$username='Monayem';
$approver='First Approver';
$requestId=12;
$message="<div class='conatiner w-50'>"."<div class='card'>"."<div class='card-header root_bg_color text-white text-center'>"."Vehicle Management System"."</div>"."<div class='card-body'>"."Dear ".$username.", "."<br><br>"."Your vehicle request( ".$requestId." ) is approved by ".$approver."."."Please visit "."<a href='http://10.12.8.8:8000/vms/public/index.php/Login'>Vehicle Management System</a> to see details."."<br><br>"."Thank You for being with Us"."</div>"."<div class='card-footer root_bg_color'></div>"."</div>"."</div>";
$email = \Config\Services::email();
$email->setTo($to);
$email->setFrom('examplemail@gmail.com', 'Vehicle Management System');
$email->setSubject($subject);
$email->setMessage($message);
if ($email->send())
{
echo 'Email successfully sent';
}
else
{
$data = $email->printDebugger(['headers']);
print_r($data);
}
echo view('template/footer.php');
}
}
它对接收者可见的方式:
我认为Bootstrap-4的CDN文件在邮件中不可用,这就是为什么设计不起作用的原因。你能帮我发送同样定制设计的电子邮件吗
让我向您展示我的代码:
namespace Config;
use CodeIgniter\Config\BaseConfig;
class Email extends BaseConfig
{
/**
* @var string
*/
public $fromEmail;
/**
* @var string
*/
public $fromName;
/**
* @var string
*/
public $recipients;
/**
* The "user agent"
*
* @var string
*/
public $userAgent = 'CodeIgniter';
/**
* The mail sending protocol: mail, sendmail, smtp
*
* @var string
*/
public $protocol = 'smtp';
/**
* The server path to Sendmail.
*
* @var string
*/
public $mailPath = '/usr/sbin/sendmail';
/**
* SMTP Server Address
*
* @var string
*/
public $SMTPHost = 'smtp.office365.com';
/**
* SMTP Username
*
* @var string
*/
// Enter your email id from where you send email
public $SMTPUser = 'exampleMail@gmail.com';
/**
* SMTP Password
*
* @var string
*/
// Enter your email's password
public $SMTPPass = 'myPassword';
/**
* SMTP Port
*
* @var integer
*/
public $SMTPPort = 587;
/**
* SMTP Timeout (in seconds)
*
* @var integer
*/
public $SMTPTimeout = 60;
/**
* Enable persistent SMTP connections
*
* @var boolean
*/
public $SMTPKeepAlive = false;
/**
* SMTP Encryption. Either tls or ssl
*
* @var string
*/
public $SMTPCrypto = 'tls';
/**
* Enable word-wrap
*
* @var boolean
*/
public $wordWrap = true;
/**
* Character count to wrap at
*
* @var integer
*/
public $wrapChars = 76;
/**
* Type of mail, either 'text' or 'html'
*
* @var string
*/
public $mailType = 'html';
/**
* Character set (utf-8, iso-8859-1, etc.)
*
* @var string
*/
public $charset = 'UTF-8';
/**
* Whether to validate the email address
*
* @var boolean
*/
public $validate = false;
/**
* Email Priority. 1 = highest. 5 = lowest. 3 = normal
*
* @var integer
*/
public $priority = 3;
/**
* Newline character. (Use “\r\n” to comply with RFC 822)
*
* @var string
*/
public $CRLF = "\r\n";
/**
* Newline character. (Use “\r\n” to comply with RFC 822)
*
* @var string
*/
public $newline = "\r\n";
/**
* Enable BCC Batch Mode.
*
* @var boolean
*/
public $BCCBatchMode = false;
/**
* Number of emails in each BCC batch
*
* @var integer
*/
public $BCCBatchSize = 200;
/**
* Enable notify message from server
*
* @var boolean
*/
public $DSN = false;
}
namespace App\Controllers;
use App\Models\FormModel;
use CodeIgniter\Controller;
class SendMail extends Controller
{
function check() {
$data['title']="Mail";
echo view('template/header.php',$data);
$to = 'exampleMail@gmail.com';
$subject = 'Vehicle Management System';
$username='Monayem';
$approver='First Approver';
$requestId=12;
$message="<div class='conatiner w-50'>"."<div class='card'>"."<div class='card-header root_bg_color text-white text-center'>"."Vehicle Management System"."</div>"."<div class='card-body'>"."Dear ".$username.", "."<br><br>"."Your vehicle request( ".$requestId." ) is approved by ".$approver."."."Please visit "."<a href='http://10.12.8.8:8000/vms/public/index.php/Login'>Vehicle Management System</a> to see details."."<br><br>"."Thank You for being with Us"."</div>"."<div class='card-footer root_bg_color'></div>"."</div>"."</div>";
$email = \Config\Services::email();
$email->setTo($to);
$email->setFrom('examplemail@gmail.com', 'Vehicle Management System');
$email->setSubject($subject);
$email->setMessage($message);
if ($email->send())
{
echo 'Email successfully sent';
}
else
{
$data = $email->printDebugger(['headers']);
print_r($data);
}
echo view('template/footer.php');
}
}
Email.php文件:
namespace Config;
use CodeIgniter\Config\BaseConfig;
class Email extends BaseConfig
{
/**
* @var string
*/
public $fromEmail;
/**
* @var string
*/
public $fromName;
/**
* @var string
*/
public $recipients;
/**
* The "user agent"
*
* @var string
*/
public $userAgent = 'CodeIgniter';
/**
* The mail sending protocol: mail, sendmail, smtp
*
* @var string
*/
public $protocol = 'smtp';
/**
* The server path to Sendmail.
*
* @var string
*/
public $mailPath = '/usr/sbin/sendmail';
/**
* SMTP Server Address
*
* @var string
*/
public $SMTPHost = 'smtp.office365.com';
/**
* SMTP Username
*
* @var string
*/
// Enter your email id from where you send email
public $SMTPUser = 'exampleMail@gmail.com';
/**
* SMTP Password
*
* @var string
*/
// Enter your email's password
public $SMTPPass = 'myPassword';
/**
* SMTP Port
*
* @var integer
*/
public $SMTPPort = 587;
/**
* SMTP Timeout (in seconds)
*
* @var integer
*/
public $SMTPTimeout = 60;
/**
* Enable persistent SMTP connections
*
* @var boolean
*/
public $SMTPKeepAlive = false;
/**
* SMTP Encryption. Either tls or ssl
*
* @var string
*/
public $SMTPCrypto = 'tls';
/**
* Enable word-wrap
*
* @var boolean
*/
public $wordWrap = true;
/**
* Character count to wrap at
*
* @var integer
*/
public $wrapChars = 76;
/**
* Type of mail, either 'text' or 'html'
*
* @var string
*/
public $mailType = 'html';
/**
* Character set (utf-8, iso-8859-1, etc.)
*
* @var string
*/
public $charset = 'UTF-8';
/**
* Whether to validate the email address
*
* @var boolean
*/
public $validate = false;
/**
* Email Priority. 1 = highest. 5 = lowest. 3 = normal
*
* @var integer
*/
public $priority = 3;
/**
* Newline character. (Use “\r\n” to comply with RFC 822)
*
* @var string
*/
public $CRLF = "\r\n";
/**
* Newline character. (Use “\r\n” to comply with RFC 822)
*
* @var string
*/
public $newline = "\r\n";
/**
* Enable BCC Batch Mode.
*
* @var boolean
*/
public $BCCBatchMode = false;
/**
* Number of emails in each BCC batch
*
* @var integer
*/
public $BCCBatchSize = 200;
/**
* Enable notify message from server
*
* @var boolean
*/
public $DSN = false;
}
namespace App\Controllers;
use App\Models\FormModel;
use CodeIgniter\Controller;
class SendMail extends Controller
{
function check() {
$data['title']="Mail";
echo view('template/header.php',$data);
$to = 'exampleMail@gmail.com';
$subject = 'Vehicle Management System';
$username='Monayem';
$approver='First Approver';
$requestId=12;
$message="<div class='conatiner w-50'>"."<div class='card'>"."<div class='card-header root_bg_color text-white text-center'>"."Vehicle Management System"."</div>"."<div class='card-body'>"."Dear ".$username.", "."<br><br>"."Your vehicle request( ".$requestId." ) is approved by ".$approver."."."Please visit "."<a href='http://10.12.8.8:8000/vms/public/index.php/Login'>Vehicle Management System</a> to see details."."<br><br>"."Thank You for being with Us"."</div>"."<div class='card-footer root_bg_color'></div>"."</div>"."</div>";
$email = \Config\Services::email();
$email->setTo($to);
$email->setFrom('examplemail@gmail.com', 'Vehicle Management System');
$email->setSubject($subject);
$email->setMessage($message);
if ($email->send())
{
echo 'Email successfully sent';
}
else
{
$data = $email->printDebugger(['headers']);
print_r($data);
}
echo view('template/footer.php');
}
}
控制器:
namespace Config;
use CodeIgniter\Config\BaseConfig;
class Email extends BaseConfig
{
/**
* @var string
*/
public $fromEmail;
/**
* @var string
*/
public $fromName;
/**
* @var string
*/
public $recipients;
/**
* The "user agent"
*
* @var string
*/
public $userAgent = 'CodeIgniter';
/**
* The mail sending protocol: mail, sendmail, smtp
*
* @var string
*/
public $protocol = 'smtp';
/**
* The server path to Sendmail.
*
* @var string
*/
public $mailPath = '/usr/sbin/sendmail';
/**
* SMTP Server Address
*
* @var string
*/
public $SMTPHost = 'smtp.office365.com';
/**
* SMTP Username
*
* @var string
*/
// Enter your email id from where you send email
public $SMTPUser = 'exampleMail@gmail.com';
/**
* SMTP Password
*
* @var string
*/
// Enter your email's password
public $SMTPPass = 'myPassword';
/**
* SMTP Port
*
* @var integer
*/
public $SMTPPort = 587;
/**
* SMTP Timeout (in seconds)
*
* @var integer
*/
public $SMTPTimeout = 60;
/**
* Enable persistent SMTP connections
*
* @var boolean
*/
public $SMTPKeepAlive = false;
/**
* SMTP Encryption. Either tls or ssl
*
* @var string
*/
public $SMTPCrypto = 'tls';
/**
* Enable word-wrap
*
* @var boolean
*/
public $wordWrap = true;
/**
* Character count to wrap at
*
* @var integer
*/
public $wrapChars = 76;
/**
* Type of mail, either 'text' or 'html'
*
* @var string
*/
public $mailType = 'html';
/**
* Character set (utf-8, iso-8859-1, etc.)
*
* @var string
*/
public $charset = 'UTF-8';
/**
* Whether to validate the email address
*
* @var boolean
*/
public $validate = false;
/**
* Email Priority. 1 = highest. 5 = lowest. 3 = normal
*
* @var integer
*/
public $priority = 3;
/**
* Newline character. (Use “\r\n” to comply with RFC 822)
*
* @var string
*/
public $CRLF = "\r\n";
/**
* Newline character. (Use “\r\n” to comply with RFC 822)
*
* @var string
*/
public $newline = "\r\n";
/**
* Enable BCC Batch Mode.
*
* @var boolean
*/
public $BCCBatchMode = false;
/**
* Number of emails in each BCC batch
*
* @var integer
*/
public $BCCBatchSize = 200;
/**
* Enable notify message from server
*
* @var boolean
*/
public $DSN = false;
}
namespace App\Controllers;
use App\Models\FormModel;
use CodeIgniter\Controller;
class SendMail extends Controller
{
function check() {
$data['title']="Mail";
echo view('template/header.php',$data);
$to = 'exampleMail@gmail.com';
$subject = 'Vehicle Management System';
$username='Monayem';
$approver='First Approver';
$requestId=12;
$message="<div class='conatiner w-50'>"."<div class='card'>"."<div class='card-header root_bg_color text-white text-center'>"."Vehicle Management System"."</div>"."<div class='card-body'>"."Dear ".$username.", "."<br><br>"."Your vehicle request( ".$requestId." ) is approved by ".$approver."."."Please visit "."<a href='http://10.12.8.8:8000/vms/public/index.php/Login'>Vehicle Management System</a> to see details."."<br><br>"."Thank You for being with Us"."</div>"."<div class='card-footer root_bg_color'></div>"."</div>"."</div>";
$email = \Config\Services::email();
$email->setTo($to);
$email->setFrom('examplemail@gmail.com', 'Vehicle Management System');
$email->setSubject($subject);
$email->setMessage($message);
if ($email->send())
{
echo 'Email successfully sent';
}
else
{
$data = $email->printDebugger(['headers']);
print_r($data);
}
echo view('template/footer.php');
}
}
namespace-App\Controllers;
使用App\Models\FormModel;
使用CodeIgniter\Controller;
类SendMail扩展控制器
{
函数检查(){
$data['title']=“邮件”;
echo视图('template/header.php',$data);
$to$exampleMail@gmail.com';
$subject=‘车辆管理系统’;
$username='Monayem';
$approver='First approver';
$requestId=12;
$message=“.”车辆管理系统“.”亲爱的“$username.”,“
”您的车辆请求(“.requestId.”)已由“$approver.”批准。“请访问“.”查看详细信息。“
”感谢您与我们在一起“.”;
$email=\Config\Services::email();
$email->setTo($to);
$email->setFrom($email)examplemail@gmail.com","车辆管理系统",;
$email->setSubject($subject);
$email->setMessage($message);
如果($email->send())
{
回显“电子邮件已成功发送”;
}
其他的
{
$data=$email->printDebugger(['headers']);
打印(数据);
}
echo视图('template/footer.php');
}
}
仅仅从bootstrap中编写类并不能使其具有神奇的样式
您必须包含来自源服务器(比如cdnjs)的css和javascript
另一方面,如果最终用户不启用javascript执行,则通过消息体发送javascript将显示为文本。
将javascript发送到电子邮件正文是一种糟糕的做法
我会选择样式而不是引导,并将您的样式包含在style
标记中
有数百个例子创建样式卡和真正酷的电子邮件正文,只是css。
例如:
我在asp.net核心MVC项目中发送电子邮件时遇到了同样的问题。然后,使用内联CSS可以节省我的时间。我想你可以接受