Can someone show me how to execute this email form. It sends the same email to everyone in "contacts.txt". I can't just <a href="email.php">Send emails now</a> I tried that but it didn't work. Can someone show me how to get it to work. Thanks <?php if (!isset($_POST['frubmit'])){ echo <<<HERE <form enctype='multipart/form-data' method='post' action='email.php'> <input type="submit" name="frubmit" value="GO! Start Emailing!" style="cursor: pointer; margin-left: 5px; margin-top: 1px; background: #20226C; color: white; width: 200px; height: 18px; font-size: 14px; border :0px;" /> </form> HERE; } // if it has been submitted then do this if (isset($_POST['frubmit'])){ $headers .= "From: <Info@mywebsite.com>\n"; // your email client will show the person's email address like normal $headers .= "Content-Type: text/plain; charset=iso-8859-1\n"; // sets the mime type $subject = "FAO Principal"; // this is the subject of the email $myFile="contacts.txt"; $msg = "Dear Sir/Madam, Our timetable for this years Tennis season will be advertised on our website soon. \n http://www.mywebsite.com \n Many thanks, Leo"; $msg = wordwrap( $msg, 1024 ); $fh = fopen($myFile, 'r') or die("Couldn't open file"); // set number of contacts by reading number of lines in file into a variable $numberoftypes = count(file($myFile)); //get the data into a large string $data = fread($fh, filesize($myFile)); fclose($fh); $array1 = explode("\r\n", $data); echo "<A href='email.php'>START AGAIN</a><BR><BR>"; for ( $botar = 0; $botar <= $numberoftypes - 1; $botar += 1 ) { $recipient = $array1[$botar]; echo "Mailing $recipient - "; $j++; if ($j==4){echo "<BR>\n";$j=0;} mail($recipient, stripslashes($subject), stripslashes($msg), $headers); // the mail() function sends the message } } ?> PHP:
Need some details but some things may cause problem like headers should be separated by "\r\n" not just "\n"
The part of the code that actually sends the mail is testing whether the form was "posted". The link will not do http post. The top portion of the code is supposed to build a button that user can click to send the mail. If its not building that button for some reason. Add this HTML code directly: <form enctype='multipart/form-data' method='post' action='email.php'> <input type="submit" name="frubmit" value="GO! Start Emailing!" style="cursor: pointer; margin-left: 5px; margin-top: 1px; background: #20226C; color: white; width: 200px; height: 18px; font-size: 14px; border :0px;" /> </form> HTML: This should create the button, and when it does, you can click on it and hte mails will be sent. Amit
Hi guys, thanks for your response. Samyak, should I add that to this same email.php or a separate file altogether? Thank you.
You can add that to the same file. If you dont mind having the button show up after the mails are sent as well.