Reputation: 3593
I am creating a form online and I need the email sent out to contain content from a file.
my headers are setup like this
@mail($email_to, $email_subject, $email_message, $headers);
and my content is here
$email_message = file_get_contents('http://www.link.co.uk/wp-content/themes/themename/email-content.php');
The file contains an email template, the problem i have is that the template is emailed out in raw format.
Here is my code:
$email_message = file_get_contents('http://www.link.co.uk/wp-content/themes/themename/email-content.php');
// create email headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
Upvotes: 1
Views: 62
Reputation: 74217
The problem here Brad, is that your headers are broken and are being overwritten.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = 'From: '.$email_from."\r\n".
add the concatenates (dots)
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$email_from."\r\n".
Concatenates are like chain links. If one is missing or there are none, something won't "hold" or gets broken. ;-) so only the last line gets processed and ignores both the MIME and HTML declarations.
$headers = 'From: '.$email_from."\r\n". ....
which is a valid declaration since it holds a valid From:
, it's just that the Email isn't "formatted" the way you wanted it to be.
Upvotes: 1
Reputation: 1345
Did you specified that your email is in HTML in your $header ?
Here is an example :
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Source : http://php.net/manual/en/function.mail.php
Upvotes: 1