Jump to content

Recommended Posts

I am trying to set up a mailing list by writing the addresses to a txt file.

 

But, i am having trouble thinking of how i could send out the mass newsletter to all of the email addresses in the file.

 

here is the code that i am using to write to the txt file

 

<?php
$filename = 'test.txt';
$somecontent = "$_POST[email]\n";

if (is_writable($filename)) {

    if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
    }

    if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }

    echo "Success, wrote ($somecontent) to file ($filename)";

    fclose($handle);

} else {
    echo "The file $filename is not writable";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/87357-solved-mailing-list/
Share on other sites

Ok i came up with the following code

 

<?php
ini_set('SMTP','smtp.vodamail.co.za');
ini_set('send_from','jaco@geekforce.co.za');

$filename='test.txt';
$arremails=file($filename);

for ($i=0;$i<=$arremails; $i++){
$subject = 'Test HTML email';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: jaco@geekforce.co.za\r\nReply-To: jaco@geekforce.co.za";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!!! 
This is simple text email message. 

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<center>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td><table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td height="23" background="http://www.itechnologies.co.za/images/a_01.gif"> <div align="left"><img src="http://www.itechnologies.co.za/images/a_01.gif" width="10" height="30"></div></td>

          <td width="66%" height="23" background="http://www.itechnologies.co.za/images/a_01.gif"><div align="right"> 
              <table border="0" cellspacing="1">
                <tr> 
                  <td><div align="left"><font face="Verdana" size="2"> <img border="0" src="http://www.itechnologies.co.za/images/b02a.gif" width="15" height="15"></font></div></td>
                  <td><div align="left"><b><font size="1"><a href="index.htm"> 
                      <font color="#FFFFFF" face="Tahoma">Home</font></a></font></b></div></td>
                  <td><div align="left"><font face="Verdana" size="2"> <img border="0" src="http://www.itechnologies.co.za/images/b02a.gif" width="15" height="15"></font></div></td>
                  <td><div align="left"><b><font size="1"><a href="contactus.htm"> 
                      <font color="#FFFFFF" face="Tahoma">Contact Us</font></a></font></b></div></td>

                  <td><div align="left"><font face="Verdana" size="2"> <img border="0" src="http://www.itechnologies.co.za/images/b01a2.gif" width="15" height="15"></font></div></td>
                  <td><div align="left"><b><font size="1"><a href="feedback.htm"> 
                      <font color="#FFFFFF" face="Tahoma">Feedback</font></a></font></b></div></td>
                  <td> <div align="left"><font face="Verdana" size="2"> <img border="0" src="http://www.itechnologies.co.za/images/d2.gif" width="15" height="15"></font></div></td>
                  <td><div align="left"><b><a href="sitemap.htm"><font color="#FFFFFF" face="Tahoma"><font size="1">Site 
                      Map</font></font></a></b></div></td>
                </tr>
              </table>

            </div></td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td width="220" rowspan="3"><div align="center">
              <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="229" height="162">
                <param name="movie" value="I%20Tech%20ad%202.swf">
                <param name="quality" value="high">

                <embed src="I%20Tech%20ad%202.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="229" height="162"></embed></object>
            </div></td>
          <td background="http://www.itechnologies.co.za/images/b_02.gif"> <img src="http://www.itechnologies.co.za/images/b_02.gif" width="10" height="54"></td>
          <td background="http://www.itechnologies.co.za/images/b_02.gif"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1"> 
            <b><a href="aboutus.htm"><font color="#FFFFFF">About Us</font></a></b><font color="#FFFFFF"><br>
            Learn how this company was started and view our values.</font></font></td>
          <td background="http://www.itechnologies.co.za/images/b_02.gif"> <div align="left"><img src="http://www.itechnologies.co.za/images/b_03.gif" width="51" height="47"></div></td>

          <td width="11" align="right" background="http://www.itechnologies.co.za/images/b_02.gif"> <div align="left"><img src="http://www.itechnologies.co.za/images/b_02.gif" width="10" height="54"></div></td>
          <td background="http://www.itechnologies.co.za/images/b_02.gif"><div align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><a href="support.htm"><font color="#FFFFFF">Support 
              We Give</font></a></b><font color="#FFFFFF"><br>
              Find support for your Bentley products here.</font></font></div></td>
          <td width="52" align="right" background="http://www.itechnologies.co.za/images/b_02.gif"><div align="right"><img src="http://www.itechnologies.co.za/images/b_04.gif" width="51" height="47"></div></td>
          <td width="12" align="right" background="http://www.itechnologies.co.za/images/b_02.gif"><div align="right"><img src="http://www.itechnologies.co.za/images/b_02.gif" width="10" height="54"></div></td>
        </tr>
        <tr> 
          <td width="10" background="http://www.itechnologies.co.za/images/b_06.gif"> <img src="http://www.itechnologies.co.za/images/b_06.gif" width="10" height="54"></td>

          <td background="http://www.itechnologies.co.za/images/b_06.gif"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1"> 
            <b><a href="whatwesell.htm"><font color="#FFFFFF">Products We Sell</font></a></b><font color="#FFFFFF"><br>
            Browse our extensive portfolio of products that we offer.</font></font></td>
          <td width="52" background="http://www.itechnologies.co.za/images/b_06.gif"> <div align="left"><img src="http://www.itechnologies.co.za/images/b_08.gif" width="51" height="47"></div></td>
          <td align="right" background="http://www.itechnologies.co.za/images/b_06.gif"> <div align="left"><img src="http://www.itechnologies.co.za/images/b_06.gif" width="10" height="54"></div></td>
          <td background="http://www.itechnologies.co.za/images/b_06.gif"><div align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><a href="training.htm"><font color="#FFFFFF">Training 
              We Offer</font></a></b><font color="#FFFFFF"><br>

              Stay up-to-date with our complete Bentley training schedule.</font></font></div></td>
          <td align="right" background="http://www.itechnologies.co.za/images/b_06.gif"><div align="right"><img src="http://www.itechnologies.co.za/images/b_10.gif" width="51" height="47"></div></td>
          <td align="right" background="http://www.itechnologies.co.za/images/b_06.gif"><div align="right"></div></td>
        </tr>
        <tr> 
          <td width="10" height="54" background="http://www.itechnologies.co.za/images/b_07.gif"> <img src="http://www.itechnologies.co.za/images/b_07.gif" width="10" height="54"></td>
          <td background="http://www.itechnologies.co.za/images/b_07.gif"> <font face="Verdana, Arial, Helvetica, sans-serif" size="1"> 
            <b><a href="servicesweoffer.htm"><font color="#FFFFFF">Services We 
            Render</font></a></b><font color="#FFFFFF"><br>

            View a list of our professional services that we offer.</font></font></td>
          <td width="52" background="http://www.itechnologies.co.za/images/b_07.gif"> <div align="left"><img src="http://www.itechnologies.co.za/images/b_09.gif" width="51" height="47"></div></td>
          <td align="right" background="http://www.itechnologies.co.za/images/b_07.gif"> <div align="left"><img src="http://www.itechnologies.co.za/images/b_07.gif" width="10" height="54"></div></td>
          <td background="http://www.itechnologies.co.za/images/b_07.gif"><div align="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><a href="resourcecenter.htm"><font color="#FFFFFF">Resource 
              Center </font></a></b><font color="#FFFFFF"><br>
              Find the skills you need by browsing our professional database.</font></font></div></td>
          <td align="right" background="http://www.itechnologies.co.za/images/b_07.gif"><div align="right"><img src="http://www.itechnologies.co.za/images/b_11.gif" width="51" height="47"></div></td>

          <td align="right" background="http://www.itechnologies.co.za/images/b_07.gif"><div align="right"></div></td>
        </tr>
      </table> </td>
  </tr>
  <tr> 
    <td> <table width="100%" border="0" cellspacing="0" cellpadding="0" background="http://www.itechnologies.co.za/images/c_01.gif">
        <tr> 
          <td width="10" height="35"> <img src="http://www.itechnologies.co.za/images/c_01.gif" width="8" height="35"></td>

          <td width="1031"> <table border="0" cellspacing="1">
              <tr> 
                <td><div align="left"><font face="Verdana" size="2"> <img border="0" src="http://www.itechnologies.co.za/images/b02a.gif" width="15" height="15"></font></div></td>
                <td><div align="left"><b><font size="1"><a href="index.htm"> <font color="#FFFFFF" face="Tahoma">Home</font></a></font></b></div></td>
                <td><div align="left"><font face="Verdana" size="2"> <img border="0" src="http://www.itechnologies.co.za/images/b02a.gif" width="15" height="15"></font></div></td>
                <td><div align="left"><b><font size="1"><a href="contactus.htm"> 
                    <font color="#FFFFFF" face="Tahoma">Contact Us</font></a></font></b></div></td>

                <td><div align="left"><font face="Verdana" size="2"> <img border="0" src="http://www.itechnologies.co.za/images/b01a2.gif" width="15" height="15"></font></div></td>
                <td><div align="left"><b><font size="1"><a href="feedback.htm"> 
                    <font color="#FFFFFF" face="Tahoma">Feedback</font></a></font></b></div></td>
                <td> <div align="left"><font face="Verdana" size="2"> <img border="0" src="http://www.itechnologies.co.za/images/d2.gif" width="15" height="15"></font></div></td>
                <td><div align="left"><b><a href="sitemap.htm"><font color="#FFFFFF" face="Tahoma"><font size="1">Site 
                    Map</font><font size="2"> </font></font> </a></b></div></td>
              </tr>

            </table></td>
        </tr>
      </table></td>
  </tr>
  <tr> 
    <td> <table width="100%" cellspacing="0" cellpadding="0">
        <tr> 
          <td valign="top" bgcolor="#FFFFFF"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td background=""> <table width="100%" border="0" cellspacing="0" cellpadding="0">

                    <tr> 
                      <td><img src="http://www.itechnologies.co.za/images/d_01d.gif" width="235" height="44"> 
                      </td>
                    </tr>
                  </table></td>
              </tr>
              <tr> 
                <td> <table width="100%" border="0" cellspacing="10" cellpadding="5" height="100%" class="content" bgcolor="#FFFFFF">
                    <tr> 
                      <td valign="top"> <font size="2" face="verdana, Arial, Helvetica"> 
                        Please tell us what you think about our web site, company, 
                        products, or services. If you provide us with your contact 
                        information,we will be able to reach you in case we have 
                        any questions.</font> </td>

                    </tr>
                    <tr> 
                      <form method="POST" action="2.php">
                        <td valign="top" align="center"><b> <font size="2" color="#175A82" face="verdana, Arial, Helvetica"> 
                          Comments:<br>
                          </font><font size="2" color="#213884"> 
                          <textarea rows="8" name="S1" cols="30"></textarea>
                          <br>
                          <br>

                          </font> <font size="2" color="175A82" face="verdana, Arial, Helvetica"> 
                          Category:<br>
                          </font></b> <select size="1" name="D1">
                            <option selected>Website Category</option>
                            <option>Introduce</option>
                            <option>About us</option>

                            <option>Product</option>
                            <option>Services</option>
                            <option>Read me</option>
                          </select> <br> <br> <table style="border-collapse: collapse" cellpadding="4">
                            <tr> 
                              <td align="right" width="80" bgcolor="whitesmoke"> 
                                <font size="2" face="verdana, Arial, Helvetica"> 
                                Name</font></td>

                              <td> <input name="Name" value size="20"> </td>
                            </tr>
                            <tr> 
                              <td align="right" bgcolor="whitesmoke"> <font size="2" face="verdana, Arial, Helvetica"> 
                                Title</font></td>
                              <td> <input name="Title" value size="20"> </td>
                            </tr>

                            <tr> 
                              <td align="right" bgcolor="whitesmoke"> <font size="2" face="verdana, Arial, Helvetica"> 
                                Company</font></td>
                              <td> <input name="Company" value size="20"> </td>
                            </tr>
                            <tr> 
                              <td align="right" bgcolor="whitesmoke"> <font size="2" face="verdana, Arial, Helvetica"> 
                                Address</font></td>

                              <td> <input name="Address" value size="20"> </td>
                            </tr>
                            <tr> 
                              <td align="right" bgcolor="whitesmoke"> <font size="2" face="verdana, Arial, Helvetica"> 
                                Telephone</font></td>
                              <td> <input name="Telephone" value size="20"> </td>
                            </tr>

                            <tr> 
                              <td align="right" bgcolor="whitesmoke"> <font size="2" face="verdana, Arial, Helvetica"> 
                                FAX</font></td>
                              <td> <input name="FAX" value size="20"> </td>
                            </tr>
                            <tr> 
                              <td align="right" bgcolor="whitesmoke" valign="top"> 
                                <font size="2" face="verdana, Arial, Helvetica"> 
                                E-mail</font></td>

                              <td> <input name="Email" value size="20"> <br> <br> 
                                 <font style="FONT-SIZE: 9pt" face="Verdana, Arial, Helvetica, sans-serif"><img src="http://www.itechnologies.co.za/images/send.gif" border="0"></font> 
                                <font style="FONT-SIZE: 9pt" face="Verdana, Arial, Helvetica, sans-serif"> 
                                <img src="http://www.itechnologies.co.za/images/reset.gif" border="0"></font> 
                              </td>
                            </tr>
                          </table></td>
                      </form>
                  </table></td>

              </tr>
            </table></td>
          <td valign="top" width="214"> <table width="214" border="0" cellspacing="0" cellpadding="0" height="100%">
              <tr align="center"> 
                <td height="42"> </td>
              </tr>
              <tr valign="top"> 
                <td align="center"></td>
              </tr>

              <tr valign="top"> 
                <td align="center"> </td>
              </tr>
              <tr valign="top"> 
                <td> </td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>

  <tr> 
    <td> <table width="100%" border="0" cellspacing="0" cellpadding="0" background="http://www.itechnologies.co.za/images/f_01.gif">
        <tr> 
          <td width="35"><img src="http://www.itechnologies.co.za/images/f_01.gif"></td>
          <td align="center"> <table border="0" cellspacing="1">
              <tr> 
                <td><font face="Verdana" size="2"> <img border="0" src="http://www.itechnologies.co.za/images/b02a.gif" width="15" height="15"></font></td>
                <td><b><font size="1"><a href="index.htm"> <font color="#FFFFFF" face="Tahoma">Home</font></a></font></b></td>

                <td><font face="Verdana" size="2"> <img border="0" src="http://www.itechnologies.co.za/images/b02a.gif" width="15" height="15"></font></td>
                <td><b><font size="1"><a href="contactus.htm"> <font color="#FFFFFF" face="Tahoma">Contact 
                  us</font></a></font></b></td>
                <td><font face="Verdana" size="2"> <img border="0" src="http://www.itechnologies.co.za/images/b01a2.gif" width="15" height="15"></font></td>
                <td><b><font size="1"><a href="feedback.htm"> <font color="#FFFFFF" face="Tahoma">Feedback</font></a></font></b></td>
                <td><font face="Verdana" size="2"> <img border="0" src="http://www.itechnologies.co.za/images/d2.gif" width="15" height="15"></font></td>

                <td><b><a href="sitemap.htm"><font color="#FFFFFF" face="Tahoma"> 
                  <font size="1">Site Map</font><font size="2">   </font></font> 
                  </a></b></td>
              </tr>
            </table></td>
          <td width="35"><img src="http://www.itechnologies.co.za/images/f_01.gif"></td>
        </tr>
      </table></td>
  </tr>

  <tr> 
    <td height="14"> <table width="100%" border="0" cellspacing="0" cellpadding="0" background="http://www.itechnologies.co.za/images/g_01.gif">
        <tr> 
          <td width="25"> <img src="http://www.itechnologies.co.za/images/g_01.gif" width="25" height="23"></td>
          <td align="center"> <font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Copyright 
            2006 i-Technologies | All rights reserved</font></td>
          <td width="25"> <img src="http://www.itechnologies.co.za/images/g_01.gif" width="25" height="23"></td>
        </tr>

      </table></td>
  </tr>
</table>
--PHP-alt-<?php echo $random_hash; ?>--
<?

//send the email

//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
mail($arremails[$i], $subject, $message, $headers);
};
?>

 

It sends the correct email to all the emails in the test.txt file but it then gives me the following errors:

 

 

Warning: mail() [function.mail]: SMTP server response: 554 Error: no valid recipients in C:\xampp\htdocs\Email\test.php on line 299

Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\Email\test.php on line 300

 

can anyone help me sothat it doesn't return errors

Link to comment
https://forums.phpfreaks.com/topic/87357-solved-mailing-list/#findComment-447056
Share on other sites

it is also forr allot of other pages to write to, it is gonna be constantly writen to and from, meaning that it'll be constantly clear for security reasons

 

You can have a lot of pages, servers or anything write to a MySQL DB, it can all be done remotely. I have kind of a pseudo code here, should work but I donno if it's what you're looking for. Do you have your mail settings set up in php.ini and or do you have an SMTP server running locally? Here's what I've come up with:

 

<?php
$file = fopen(file.txt,"r");
$addys=explode("\n" $file);
fclose($file);
$i = 0;
For $i < count($addys)
{
mail($addys[$i],$subject,$message);
$i++;
}
?>

 

that would do what you want I think.

Link to comment
https://forums.phpfreaks.com/topic/87357-solved-mailing-list/#findComment-451371
Share on other sites

Actually that was stupid, it can be done very simply. I forgot about foreach() >_<

 

<?php
$subject = $_POST['subject'];
$message = $_POST['message'];
$file = fopen(file.txt,"r");
$addys = explode("\n" $file);
fclose($file);
foreach ($addys as $addy)
{
mail($addy,$subject,$message);
}
?>

 

Set up your mail settings in php.ini and run a SMTP server. Or you could even set it up to use an outside email like gmail, just put the info in php.ini. No need to fuss with that within the PHP.

Link to comment
https://forums.phpfreaks.com/topic/87357-solved-mailing-list/#findComment-451374
Share on other sites

C:\xampp\htdocs\Email\test.php on line 299

I think it's the amount of reciepents.

299 is a bit ecessive for 1 email.

 

break em into 20-25 reciepents per mail

 

Using foreach() the emails are sent 1 at a time, they're not all sent at the same time. Thus this shouldn't matter.

Link to comment
https://forums.phpfreaks.com/topic/87357-solved-mailing-list/#findComment-451375
Share on other sites

with the modified code it's still giving me an error

 

Warning: mail() [function.mail]: SMTP server response: 501 Bad address syntax in C:\xampp\htdocs\Email\New Folder (3)\test1.php on line 16

 

<?php
ini_set('SMTP','smtp.vodamail.co.za');
ini_set('send_from','addy.co.za');
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: addy.co.za\r\nReply-To: addy.co.za";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
$subject = $_POST['subject'];
$message = $_POST['message'];
$file = fopen('test.txt',"r");
$addys = explode("\n", $file);
fclose($file);
foreach ($addys as $addy)
{
mail($addy,$subject,$message,$headers);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/87357-solved-mailing-list/#findComment-451412
Share on other sites

use something like a preg_match statement to check for valid email addresses.

 

/** Checks is the provided email address is formally valid
*  @param string $email email address to be checked
*  @return true if the email is valid, false otherwise
*/
function valid_email($email) {
  $regexp="/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
  if ( !preg_match($regexp, $email) ) {
       $_obweb->addErr("Email address is not correct\n");
       return false;
  }
  return true;
}

Link to comment
https://forums.phpfreaks.com/topic/87357-solved-mailing-list/#findComment-451497
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.