Execute this email form

Discussion in 'PHP' started by le007, Mar 16, 2012.

  1. #1
    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 &nbsp;&nbsp;&nbsp; - ";
    $j++;
    if ($j==4){echo "<BR>\n";$j=0;}
    
    mail($recipient, stripslashes($subject), stripslashes($msg), $headers); // the mail() function sends the message
    
    }
    
    }
    ?>
    PHP:
     
    Solved! View solution.
    le007, Mar 16, 2012 IP
  2. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Need some details but some things may cause problem

    like headers should be separated by "\r\n" not just "\n"
     
    stOK, Mar 16, 2012 IP
  3. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #3
    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
     
    samyak, Mar 16, 2012 IP
  4. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    Hi guys, thanks for your response.

    Samyak, should I add that to this same email.php or a separate file altogether?

    Thank you.
     
    le007, Mar 16, 2012 IP
  5. #5
    You can add that to the same file. If you dont mind having the button show up after the mails are sent as well.
     
    samyak, Mar 18, 2012 IP
  6. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #6
    Thanks a million samyak ",)
     
    le007, Mar 21, 2012 IP