我想发送HTML内容与CSS电子邮件使用php.这是我目前为止学到的.所有的工作,但在电子邮件中看到的内容是不解释的.&



这是我发送电子邮件的代码。file_get_contents ();我检索的是纯文本格式的内容。CSS样式不读取

<?php

use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
include 'connection.php';
$conn = new Connection();
if(!$conn->connect()) die('Configuration error');
echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."<br />";
$to_decode = json_decode(file_get_contents("php://input"));
$email = $to_decode->email;
$mail = new PHPMailer(true);
$template = "template.php";
$dom_details = array(
"{my-website}" => "Sample Website",
"{my-number}" => "Country-State-Local Code-Number",
"{my-message}" => 'MIKOMIKO'
);
if(file_exists($template))
$temp_message = file_get_contents($template);
else
die("Template file not found!");

foreach(array_keys($dom_details) as $key){
$temp_message = str_replace($key, $dom_details[$key], $temp_message);
}
try{
$mail->isSMTP();                                        // Send using SMTP
$mail->Host       = 'smtp.gmail.com';                   // Set the SMTP server to send through
$mail->SMTPAuth   = true;                               // Enable SMTP authentication
//use your own account details
//if you are using a gmail account, turn on less secured app under security
$mail->Username   = 'mikocoral11@gmail.com';            // SMTP username
$mail->Password   = 'ssss';                    // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;     // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port       = 587;                                // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('mikocoral11@gmail.com');
$mail->addAddress($email);     // Add a recipient
//$mail->addCC('xxxxxx@gmail.com');
$mail->Subject = 'welcmoe blog to my guys';
$mail->Body    = $temp_message;

//$mail->IsHTML(true);
$mail->send();
echo 'Message Sent';
} catch (Exception $e){
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>

这是模板的内容,我需要在电子邮件

<html>
<head>
</head>
<body style="background-color:ddd;">
<div style="margin: auto; width: 40%; text-align: center; font-size: 20px; padding: 1% 2% 3% 3%; background-color: eee; border-radius: 12px; margin-top: 3%;">
<h1>Hi {client-name}!</h1><hr /><br />
<span>Welcome to {my-website}. Your new account comes with access to all features and services.
To get started, click the button below to active your account.</span>
<br />
<br />
<a href="http://localhost/activities/SystemInteg/include-mailer-email-html-2">
<button style="padding: 1%; background-color:#045791; border-radius:8px;">
<span style="font-size: 20px; color: white;">Activate</span>
</button>
</a><br />
<br />
<p>For any concerns, kindly call or text us at {my-number}.</p>
<p>Additional message goes here: Visit {website}</p>
</div>
</body>
</html>

这是我收到的邮件。正如您所看到的,HTML和CSS样式的所有元素都是纯文本格式。和模板完全一样。请帮助我如何才能使它与此代码提供的工作。谢谢!

<html>
<head>
</head>
<body style="background-color:ddd;">
<div style="margin: auto; width: 40%; text-align: center; font-size: 20px; padding: 1% 2% 3% 3%; background-color: eee; border-radius: 12px; margin-top: 3%;">
<h1>Hi {client-name}!</h1><hr /><br />
<span>Welcome to Sample Website. Your new account comes with access to all features and services.
To get started, click the button below to active your account.</span>
<br />
<br />
<a href="http://localhost/activities/SystemInteg/include-mailer-email-html-2">
<button style="padding: 1%; background-color:#045791; border-radius:8px;">
<span style="font-size: 20px; color: white;">Activate</span>
</button>
</a><br />
<br />
<p>For any concerns, kindly call or text us at Country-State-Local Code-Number.</p>
<p>Additional message goes here: Visit {website}</p>
</div>
</body>
//$mail->IsHTML(true);

取消上面的注释,所以phpmailer发送HTML邮件

相关内容

  • 没有找到相关文章

最新更新