Search
Close this search box.

Send email template with file_get_contents in wordpress

Amitpal Singh
Amitpal Singh
August 3, 2020
$body = file_get_contents(WP_CONTENT_DIR . '/themes/theme-name/emailtemplate.html'); 
$body = str_replace("#name#",$_POST['name'],$body);
$body = str_replace("#email#",'<a style="color:#fff" href="mailto:'.$_POST['email'].'">'.$_POST['email'].'</a>',$body);
$body = str_replace("#mobile#",$_POST['mobile'],$body);
$body = str_replace("#message#",$_POST['message'],$body);


$to = "admin@email.com";
$headers = 'From: "' . $name. '" <no-reply@company.com>' . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";

	
mail( $to, $subject, $body, $headers );

Share this post:

How to Attribute?

Lorem ipsum is typically a corrupted version of De finibus bonorum et malorum, a 1st-century BC text by the Roman statesman and philosopher Cicero.
for Example: Website, Social Media, Blogs, ebooks , newsletter, etc.
Lorem ipsum is typically a corrupted version of De finibus bonorum et malorum, a 1st-century BC text by the Roman statesman and philosopher Cicero.
Copied!

Got a Question? Check out our FAQ Section.

Your action, our appreciation

It encourage us to give you more valuable content on website.