问题
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