Отправлять почту php с помощью emails.txt и настраиваемого сообщения из message.txt

Я пытаюсь отправить электронное письмо с помощью PHP. У меня есть файл emails.txt со списком писем и имен, разделенных символом ';' и у меня также есть content.txt с сообщением электронной почты, например, «Hello Mr. $ name»

Я хочу отправить электронное письмо всем пользователям с помощью файла content.txt и изменить имя $ name с помощью emails.txt, чтобы заменить строку $ name

Я построил несколько частей, но я застрял

<?php $file = fopen("emails.txt", "r"); $filecontent = fopen("content.txt", "r"); while(!feof($file)){ $line = fgets($file); $to = $line; $subject = "This is subject"; $message = "<b>This is HTML message.</b>"; $message .= "<h1>This is headline.</h1>"; $header = "From:abc@somedomain.com \r\n"; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-type: text/html\r\n"; $retval = mail ($to,$subject,$message,$header); if( $retval == true ) { echo "Message sent successfully..."; }else { echo "Message could not be sent..."; } } fclose($file); ?> 

другая часть

 <?php $path_to_file = 'content.txt'; $file_contents = file_get_contents($path_to_file); $file_contents = str_replace("$name","$correctname",$file_contents); file_put_contents($path_to_file,$file_contents); ?>