Valid Send Mail Function with PHP

Written by @kerixa 11 September 2020

Although it seems that sending mail with PHP is very easy and there exists a function that simply does the job, it is not as it should be. Yes! Some hidden options highly affect this mailing function and, in fact, sometimes lead to failure. The following snippet helps yo use PHP mailing capacity truly and easily. Enjoy!

Code Snippet:

                                                
                                                <!-- this script is provided by https://www.phpfreecode.com coded by: Kerixa Inc. -->
function sendmail($to,$subject,$title,$content){
	$mailfrom   = "no-reply@freewebsonline.com";
	$headers    = "From: Free Webs Online <" . strip_tags($mailfrom) . ">\r\n";
	$headers    .= "Reply-To: ". strip_tags($mailfrom) . "\r\n";
	$headers    .= "MIME-Version: 1.0\r\n";
	$headers    .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
	$ftemp      = dirname(__FILE__).'/mailtemplate.htm';
	$file       = fopen($ftemp,"r");
    $template   = fread($file,filesize($ftemp));
    fclose($file);
	$message    = replace_all($template,'%title%',$title);
	$message    = replace_all($message,'%content%',$content);
	return mail($to,$subject,$message,$headers);
}<a target='_blank' href='https://www.phpfreecode.com' style='font-size: 8pt; text-decoration: none'>Php Best Codes</a>                                                
                                            

Example:


About @kerixa

I am Krishna Eydat. I studied Software Engineering at University of Waterloo in Canada. I lead a few tech companies. I am passionate about the way we are connected. I would like to be part of something big or be the big deal!

K

Comments


Here you can leave us commments. Let us know what you think about this code tutorial!

0 / 300

TRENDING POST
1
2
3
4
5
VISITORS
Online Users: 12
Recent Members: grkkid, Manaakividuinfo.com, karticksv, sava, tinatina
advertisement 2