zacthespack Posted October 11, 2010 Share Posted October 11, 2010 I found a newsletter script called 'easy newsletter' which allows me to set up a page for users to sign up to a news letter emailing list. There is then another page that a admin can log into and create a simple text email to send out to everyone that has signed up. My problems is i require the email to include a attachment and have no clue how i can add this to the script to get it working. Can anyone help me? The script that sends out the email is included below if this helps: <?php //load configuration require("config.php"); //connect to database @mysql_connect($db_server,$db_user,$db_password) or die("Database server connection failed. Check variables \$db_server, \$db_user and \$db_password in config.php"); @mysql_select_db($db_name) or die("Selecting database failed. Check variable \$db_name in config.php"); //print header echo $header; ?> <h1><?php echo $title; ?> - Administration</h1> <hr> <?php $pwd = $_GET["pwd"]; //simple login if(isset($pwd) && ($pwd == $password)){ $submit = $_POST["submit"]; $submit_newsletter = $_POST["submit_newsletter"]; $del = $_GET["del"]; //insert new address if(isset($submit)){ $name = $_POST["name"]; $email = $_POST["email"]; @mysql_query("INSERT INTO $db_table (email,name) VALUES ('$email','$name');"); //error occurred if(@mysql_error()){ ?><p>Inserting entry failed: <?php echo @mysql_error(); ?></p> <p><a href="javascript:history.back();">Click here to go back.</a></p><?php //successful }else{ ?><p>Entry has been inserted successfully. <a href="admin.php?pwd=<?php echo $pwd; ?>">Click here to continue.</a></p><?php } //delete an entry }else if(isset($del)){ @mysql_query("DELETE FROM $db_table WHERE id=$del;"); //error occurred if(@mysql_error()){ ?><p>Deleting entry failed: <?php echo @mysql_error(); ?></p> <p><a href="javascript:history.back();">Click here to go back.</a></p><?php //successful }else{ ?><p>Entry has been deleted successfully. <a href="admin.php?pwd=<?php echo $pwd; ?>">Click here to continue.</a></p><?php } //send newsletter }else if(isset($submit_newsletter)){ $sent = 0; $result = @mysql_query("SELECT name,email FROM $db_table ORDER BY email ASC;"); $subject = $_POST["subject"]; $message = $_POST["message"]; ?><p>Sending emails to ...</p> <ul><?php //send emails one by one while($row=@mysql_fetch_array($result)){ $name = $row["name"]; $email = $row["email"]; ?><li><?php echo $name; ?> (<?php echo $email; ?>) ... <?php if(@mail($email,$subject,$message,"From: $admin <$admin>\n")){ ?>sent<?php $sent++; }else{ ?>failed<?php } ?></li><?php } ?></ul> <p><strong><?php echo $sent; ?> emails sent.</strong> <a href="admin.php?pwd=<?php echo $pwd; ?>">Click here to continue.</a></p><?php //print forms }else{ ?><h2>Send newsletter</h2> <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>?pwd=<?php echo $pwd; ?>"> <table> <tr> <td>Subject:</td> <td><input type="text" name="subject" class="fixedwidth"></td> </tr> <tr> <td valign="top">Message:</td> <td><textarea name="message" cols="60" rows="20" class="fixedwidth"><?php echo $signature; ?></textarea></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit_newsletter" value="Send"></td> </tr> </table> </form> <h2>Add an email address</h2> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>?pwd=<?php echo $pwd; ?>" method="post"> <table> <tr> <td>Name:</td> <td><input type="text" name="name" value="" maxlength="255"></td> </tr> <tr> <td>Email address:</td> <td><input type="text" name="email" value="" maxlength="255"></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="Submit"></td> </tr> </table> </form> <h2>Email addresses</h2> <table cellpadding="5" cellspacing="2"> <tr class="header"> <td><strong>Name</strong></td> <td><strong>Email address</strong></td> <td> </td> </tr> <?php $result = @mysql_query("SELECT * FROM $db_table ORDER BY email ASC;"); $colored = false; while($row=@mysql_fetch_array($result)){ $colored = !$colored; ?><tr<?php if($colored){ ?> class="colored"<?php } ?>> <td width="200"><?php echo $row["name"]; ?></td> <td width="200"><?php echo $row["email"]; ?></td> <td><a href="<?php echo $_SERVER["PHP_SELF"]; ?>?pwd=<?php echo $pwd; ?>&del=<?php echo $row["id"]; ?>">remove</a></td> </tr><?php } ?> </table> <?php } }else{ //print login form echo $login; } //print link to news ?><p align="right"><a href="index.php">Newsletter</a></p><?php //print footer echo $footer; //close database connection @mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/215624-help-adding-attachment-to-php-newsletter-script/ Share on other sites More sharing options...
BlueSkyIS Posted October 11, 2010 Share Posted October 11, 2010 the hard way (imo): add mime headers, mime boundaries and all that stuff the easy way (imo): use an existing class to attach files simply. I use this: http://www.phpguru.org/downloads/Rmail/ Link to comment https://forums.phpfreaks.com/topic/215624-help-adding-attachment-to-php-newsletter-script/#findComment-1121108 Share on other sites More sharing options...
zacthespack Posted October 11, 2010 Author Share Posted October 11, 2010 Thank you very much, sorry i have very little experience with PHP, could you tell me step by step how to do either methods (im guessing the easy one would be easier to explain)? Link to comment https://forums.phpfreaks.com/topic/215624-help-adding-attachment-to-php-newsletter-script/#findComment-1121115 Share on other sites More sharing options...
BlueSkyIS Posted October 11, 2010 Share Posted October 11, 2010 they include an excellent example here: http://www.phpguru.org/downloads/Rmail/Rmail%20for%20PHP/example.phps Link to comment https://forums.phpfreaks.com/topic/215624-help-adding-attachment-to-php-newsletter-script/#findComment-1121116 Share on other sites More sharing options...
zacthespack Posted October 11, 2010 Author Share Posted October 11, 2010 ok thank you i will see what i can mash together Link to comment https://forums.phpfreaks.com/topic/215624-help-adding-attachment-to-php-newsletter-script/#findComment-1121120 Share on other sites More sharing options...
zacthespack Posted October 11, 2010 Author Share Posted October 11, 2010 am i right in saying you have to edit the php script everytime you want to send a different attachment/to a different person? Link to comment https://forums.phpfreaks.com/topic/215624-help-adding-attachment-to-php-newsletter-script/#findComment-1121125 Share on other sites More sharing options...
zacthespack Posted October 12, 2010 Author Share Posted October 12, 2010 Bump.....I still really need help with this is there anyone else that can help me? Link to comment https://forums.phpfreaks.com/topic/215624-help-adding-attachment-to-php-newsletter-script/#findComment-1121385 Share on other sites More sharing options...
BlueSkyIS Posted October 12, 2010 Share Posted October 12, 2010 am i right in saying you have to edit the php script everytime you want to send a different attachment/to a different person? no. modify the script to look up an email address in a database, or take one or more email addresses as input. Link to comment https://forums.phpfreaks.com/topic/215624-help-adding-attachment-to-php-newsletter-script/#findComment-1121466 Share on other sites More sharing options...
zacthespack Posted October 12, 2010 Author Share Posted October 12, 2010 am i right in saying you have to edit the php script everytime you want to send a different attachment/to a different person? no. modify the script to look up an email address in a database, or take one or more email addresses as input. Is it possible to set it up just to take every email address in the database? Link to comment https://forums.phpfreaks.com/topic/215624-help-adding-attachment-to-php-newsletter-script/#findComment-1121478 Share on other sites More sharing options...
BlueSkyIS Posted October 12, 2010 Share Posted October 12, 2010 yes. you could simply select all email addresses and email each one separately, or in groups via an array. but that might not be the best way, depending on the size of the database. if you have 200,000 email addresses, the script will time out before it finishes sending them all. in that case it might be better to store the outbound email addresses in a table and send smaller groups of them with the script scheduled to run via crontab. Link to comment https://forums.phpfreaks.com/topic/215624-help-adding-attachment-to-php-newsletter-script/#findComment-1121480 Share on other sites More sharing options...
zacthespack Posted October 12, 2010 Author Share Posted October 12, 2010 yes. you could simply select all email addresses and email each one separately, or in groups via an array. but that might not be the best way, depending on the size of the database. if you have 200,000 email addresses, the script will time out before it finishes sending them all. in that case it might be better to store the outbound email addresses in a table and send smaller groups of them with the script scheduled to run via crontab. is there not another way i can add what i need to the script i already have, i have tried and tried getting it to send a attachment with the email script i have but i just cant get it to work. Link to comment https://forums.phpfreaks.com/topic/215624-help-adding-attachment-to-php-newsletter-script/#findComment-1121513 Share on other sites More sharing options...
zacthespack Posted October 13, 2010 Author Share Posted October 13, 2010 Bump......could still real use help Link to comment https://forums.phpfreaks.com/topic/215624-help-adding-attachment-to-php-newsletter-script/#findComment-1121730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.