[英]How to send a html / html5 template email with php?
I want to send a html / html5 email with PHP. 我想用PHP发送html / html5电子邮件。 I have a html template with the email message which I am planning to send to a user. 我有一个HTML模板,其中包含我打算发送给用户的电子邮件。
HTML template - default-message.php HTML模板 -default-message.php
<?php include 'mailservice.php'; ?>
<div>
<h3>Dear <?php echo $name; ?>,</h3>
<p>I send you this custom message!!</p>
</div>
PHP - mailservice.php PHP - mailservice.php
/* getting the content from te default-message.html file*/
ob_start();
include('default-message.php');
$message = ob_get_contents();
ob_end_clean();
$name = "John";
$to = "sadas@yahoo.com";
$subject = "Hello";
$headers .= 'From: Me <abc@mysite.com>' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail ($to, $subject, $message, $headers);
You need to set the variables before you include the template script, so they'll be expanded when the template runs. 您需要在包含模板脚本之前设置变量,以便在模板运行时将其展开。
ob_start();
$name = "John";
$to = "sadas@yahoo.com";
include('default-message.html');
$message = ob_get_contents();
ob_end_clean();
$subject = "Hello";
$headers .= 'From: Me <abc@mysite.com>' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail ($to, $subject, $message, $headers);
Also, default-message.html
should not contain <?php include 'mailservice.php'; ?>
另外, default-message.html
不应包含<?php include 'mailservice.php'; ?>
<?php include 'mailservice.php'; ?>
, because then it will go back and forth with each script including the other. <?php include 'mailservice.php'; ?>
,因为它随后将与每个脚本(包括另一个脚本)一起来回移动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.