简体   繁体   中英

php send email: include email html in seperate file using php?

i have a button on my index / home page:

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

When this is clicked it runs my mysql query in action.php and after i have run my query i want to send out an email. So after the query has executed i include my send_email.php file:

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

include 'send email.php'

in send_email.php i have:

<?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";

?>

As you can see I am trying to include my email html as a seperate php file stored in assets/email/index.php. i am trying to do it this way so the email can be easily edited at a later date.

However using this method doesnt work. The email is sent but its blank without any HTML. Also after the query has executed it takes you to the email html page/index.php.

an illustration of my email 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>

Why is this? when it should be echoing 'Updated data Succesfully' and be sending the email with html?

Can someone please show me what i am doing wrong? Thanks

You are trying to send a message store in a php file, right? That won't work. You should use file_get_contents to get the HTML content as a string and assign it to the $message variable, and not by simply including it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM