php发送电子邮件:使用php在单独的文件中包含电子邮件html?

时间:2015-03-13 12:24:53

标签: php include sendmail

我的索引/主页上有一个按钮:

<a href="action.php">click</a>

当点击它时,它在action.php中运行我的mysql查询,在我运行查询后,我想发送一封电子邮件。所以在查询执行后我包含了我的send_email.php文件:

$query = "update table1 SET action = '1' WHERE something = something";
$result = mysql_query($query);

include 'send email.php'
send_email.php中的

我有:

<?php
date_default_timezone_set("Europe/London");
// multiple recipients
$to  = "jason.horsfall@hewden.co.uk"; // 

// subject
$subject = 'New Supplier Set-Up - Hewden Portal';

// message
$message = include '../../assets/email/index.php';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mark <jason.horsfall@hewden.co.uk>'. "\r\n";
$headers .= 'From: Hewden Portal <SupplierSetup@Hewden.co.uk>' . "\r\n";
$headers .= "Cc: mark.o'brian@hewden.co.uk" . "\r\n";


// Mail it
mail($to, $subject, $message, $headers);

echo "Updated data successfully\n";

?>

正如您所看到的,我正在尝试将我的电子邮件html包含为存储在assets / email / index.php中的单独的php文件。我试图这样做,以便以后可以轻松编辑电子邮件。

然而,使用此方法不起作用。电子邮件已发送,但其空白,没有任何HTML。在执行查询之后,它还会将您带到电子邮件html page / index.php。

我的电子邮件html / index.php的插图:

<html>
<Body>
<p>This is my email template</p>
<p>More Text here bla bla</p>
<style>
Some CSS
</style>
</body>
</html>

这是为什么?什么时候应该回应'更新数据成功'并发送电子邮件与html?

有人可以告诉我我做错了什么吗?感谢

1 个答案:

答案 0 :(得分:0)

您正在尝试在php文件中发送邮件存储,对吗?那不会奏效。您应该使用file_get_contents将HTML内容作为字符串获取并将其分配给$ message变量,而不是仅仅包含它。