Help with newsletter mailing script

the mail() function

Moderators: egami, macek, gesf

Post Reply
ezeuba
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Mar 06, 2018 1:42 pm

Tue Mar 06, 2018 1:50 pm

Hello everyone. I'm new to PHP and also new here. I have a website and I have a script which worked before but then my site was hacked and I had to clean up, but the newsletter script is no longer working. It throws a lot of undefined variable erros and like I said I'm not very proficient with PHP; the script was coded for me by a friend who is no longer around now to help in figuring this out.
Here is the script. Please help me locate why there are errors all over it when I try to run it.
Thanks.

Code: Select all

<?php
if(isset($_POST['action'] ) ){
$action=$_POST['action'];
$message=$_POST['message'];
$emaillist=$_POST['emaillist'];
$from=$_POST['from'];
$replyto=$_POST['replyto'];
$subject=$_POST['subject'];
$realname=$_POST['realname'];
$file_name=$_POST['file'];
$contenttype=$_POST['contenttype'];

        $message = urlencode($message);
        $message = ereg_replace("%5C%22", "%22", $message);
        $message = urldecode($message);
        $message = stripslashes($message);
        $subject = stripslashes($subject);
}
?>

<form name="form1" method="post" action="" enctype="multipart/form-data">
  <br>
  <table width="100%" border="0">
    <tr>
      <td width="10%">
        <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Your
          Email:</font></div>
      </td>
      <td width="18%"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
        <input type="text" name="from" value="<?php print $from; ?>" size="30">
        </font></td>
      <td width="31%">
        <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Your
          Name:</font></div>
      </td>
      <td width="41%"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
        <input type="text" name="realname" value="<?php print $realname; ?>" size="30">
        </font></td>
    </tr>
    <tr>
      <td width="10%">
        <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Reply-To:</font></div>
      </td>
      <td width="18%"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
        <input type="text" name="replyto" value="<?php print $replyto; ?>" size="30">
        </font></td>
      <td width="31%">
        <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Attach
          File:</font></div>
      </td>
      <td width="41%"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
        <input type="file" name="file" size="30">
        </font></td>
    </tr>
    <tr>
      <td width="10%">
        <div align="right"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">Subject:</font></div>
      </td>
      <td colspan="3"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
        <input type="text" name="subject" value="<?php print $subject; ?>" size="90">
        </font></td>
    </tr>
    <tr valign="top">
      <td colspan="3"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
        <textarea name="message" cols="60" rows="10"><?php print $message; ?></textarea>
        <br>
        <input type="radio" name="contenttype" value="plain" >
        Plain Text
        <input name="contenttype" type="radio" value="html" checked>
        HTML
        <input type="hidden" name="action" value="send">
        <input type="submit" value="Send">
        </font></td>
      <td width="41%"><font size="-3" face="Verdana, Arial, Helvetica, sans-serif">
        <textarea name="emaillist" cols="30" rows="10"><?php //print $emaillist; ?></textarea>
        </font></td>
    </tr>
  </table>
</form>
<?php
if ($action){
        if (!$from && !$subject && !$message && !$emaillist){
        print "Please Complete All Fields Before Sending Your Message.";
        exit;
	}
	$allemails = split("\n", $emaillist);
        	$numemails = count($allemails);
          for($x=0; $x<$numemails; $x++){
                $to = $allemails[$x];
                if ($to){
                $to = ereg_replace(" ", "", $to);
                $message = ereg_replace("&email&", $to, $message);
                $subject = ereg_replace("&email&", $to, $subject);
                print "Sending Mail to $to.......";
                flush();
                $header = "From: $realname <$from>\r\nReply-To: $replyto\r\n";
                $header .= "MIME-Version: 1.0\r\n";
                $header .= "Content-Type: text/$contenttype\r\n";
                $header .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
                $header .= "$message\r\n";
              mail($to, $subject, "", $header);
                print "via Newsletter Mailer<br>";
                flush();                }
                }
};
?>

<?php
if(isset($_POST['action']) && $numemails !==0 ){echo "<script>alert('Done!\\r\\n$numemails mail(s) sent successfully!'); </script>";}
?>
<?php exit() ?>

Post Reply