Send php mail using emails.txt and custom message from message.txt

北城以北 提交于 2019-12-11 02:42:26

问题


I'm trying to send email using PHP I have emails.txt with a list of emails and names split by ';' and I also have content.txt with the email message, for example, "Hello Mr. $name"

I want to send an email, for all users, using content.txt file and alter the $name using the emails.txt to replace the string $name

I built some parts, but I'm stuck

  <?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);


  ?>

another part

<?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);

?>

来源:https://stackoverflow.com/questions/37925139/send-php-mail-using-emails-txt-and-custom-message-from-message-txt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!