Dark

Light

Dark

Light

Scroll to top

Send email template with file_get_contents in wordpress

$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 = "[email protected]";
$headers = 'From: "' . $name. '" <[email protected]>' . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";

	
mail( $to, $subject, $body, $headers );
Author avatar
Amitpal Singh
https://amitpalsingh.com

Post a comment

Your email address will not be published. Required fields are marked *