PHP - Help Making A Newsletter Email System
For my A level ICT i need to create a PHP newsletter email system for which people can sign up from one page and then a admin can log in and send out the email to the people that have signed up. My problem is i also need to attach a PDF to these emails, however i cant work out how to add this into the scripts i have for the newsletter system. Even my teacher cant help me , please can someone help me .
The code i have is below. admin.php <?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&#058;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&#058;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(); ?> config.php <?php /* ######################## DATABASE ######################## */ // Database server $db_server = "localhost"; // Database name $db_name = "zpwebsi1_news"; // Database username $db_user = "zpwebsi1_zac"; // Database password $db_password = "powell"; // Database table to store news // (will be created automatically) $db_table = "easy_newsletter"; /* ##################### CONFIGURATION ###################### */ // Complete URL of the script // (begins with http://, ends with slash) $url = "http://www.charsfieldthreehorseshoes.co.uk/alemail.html"; // Password for the administration $password = "admin"; // Administrator email address (will be used as sender of // the newsletter emails) $admin = "zac@zpwebsite.com"; // Title (will be displayed in the browser's header $title = "Ale Mail"; // Signature (will be inserted when creating a fresh // newsletter but can be changed before submitting) $signature = "\n\n\n\n\n---------------------\nYou receive this email because you have registered with our newsletter $title. Click the following link to unsubscribe: $url"; /* ######################### LAYOUT ######################### */ // Header to be used on each page $header = <<<EOT <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="style.css" rel="stylesheet" type="text/css"> <title>$title</title> </head> <body> EOT; // Footer to be used on each page $footer = <<<EOT </body> </html> EOT; // Login form $login = <<<EOT <form action="admin.php" method="get"> Password: <input name="pwd" type="password"> <input type="submit" value="Login"> </form> EOT; ?> And index.php <?php //load configuration require("config.php"); //print header echo $header; ?> <h1><?php echo $title; ?></h1> <hr> <?php //form submitted if(isset($_POST["submit"])){ //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"); $name = $_POST["name"]; $email = $_POST["email"]; //subscribe if($_POST["action"]=="subscribe"){ //check if name is long enough if(strlen($name)<3){ ?><p>Name must consist of at least 3 characters.</p><?php //check if email is valid }else if(!eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$",$email)){ ?><p>Email address is not valid.</p><?php //check if email already exists }else if(@mysql_num_rows(@mysql_query("SELECT id FROM $db_table WHERE email='$email';"))){ ?><p>Email address exists already.</p><?php //insert values }else{ @mysql_query("INSERT INTO $db_table (email,name) VALUES ('$email','$name');"); //error occurred if(@mysql_error()){ ?><p>An unknown error occurred. Please try again later.</p><?php //successful }else{ ?><p>Subscription was successful. Thank you!</p><?php } } //unsubscribe }else{ @mysql_query("DELETE FROM $db_table WHERE email='$email';"); //error occurred if(@mysql_error()){ ?><p>An unknown error occurred. Please try again later.</p><?php //email not found }else if(@mysql_affected_rows()==0){ ?><p>Email address not found.</p><?php //successful }else{ ?><p>You have unsubscribed successfully!</p><?php } } } ?> <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"> <table> <tr> <td>Your name:</td> <td><input type="text" name="name" value="" maxlength="255"></td> </tr> <tr> <td>Your email address:</td> <td><input type="text" name="email" value="" maxlength="255"></td> </tr> <tr> <td> </td> <td><input type="radio" name="action" value="subscribe" id="action_subscribe" checked> <label for="action_subscribe">subscribe</label> <input type="radio" name="action" value="unsubscribe" id="action_unsubscribe"> <label for="action_unsubscribe">unsubscribe</label></td> </tr> <tr> <td> </td> <td><input type="submit" name="submit" value="Submit"></td> </tr> </table> </form> <p align="right"><a href="admin.php">Administration</a></p> <?php //print footer echo $footer; //close database connection @mysql_close(); ?> Similar TutorialsWhat would be the most efficient way of letting my administrators make a poll? I want them to be able to set how many options (all options will be a radiobutton) they wish to have in the poll. I'm basically stuck on the part of: how would I store the poll options. Would I make separate table then store all the questions in there with the ID of the poll they created? This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=349747.0 I have database table EMAIL[e_id,receiver_email,sender_email,email_Subject,date_time,Text_body] i have displayed sender_email,Email_subject,Date_time in html table by using select sender_email,Email_subject,Date_time from email where receiver_email=$current _user i need to open email_body by clicking the sender_email problem is that how can i get value of first cell of table in the same row by clicking any other column or if you have alternative as yahoo displayes all emails received in inbox by clicking any sender it opens that specific email For some reason my email system isnt working, but no errors are showing up and i cant seem to find a syntax error. I need some fresh eyes to help to solve this... Code: [Select] <?php if(isset($_POST['PersonName'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "j.hopley@2008.ljmu.ac.uk"; $email_subject = "An email from your blog."; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['PersonName']) || !isset($_POST['PersomComment']) || !isset($_POST['PersonEmail']) || !isset($_POST['PersonNumber'])) { died('We are sorry, but there appears to be a problem with the form you submitted. One or more fields were empty or contained invailid charicters.'); } $person_name = $_POST['PersonName']; // required $person_comment = $_POST['PersomComment']; // required $person_email = $_POST['PersonEmail']; // required $person_number = $_POST['PersonNumber']; // not required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$person_email)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$person_name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } if(strlen($person_comment) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($person_name)."\n"; $email_message .= "Email: ".clean_string($person_email)."\n"; $email_message .= "Telephone: ".clean_string($person_number)."\n"; $email_message .= "Comments: ".clean_string($person_comment)."\n"; // create email headers $headers = 'From: '.$person_email."\r\n". 'Reply-To: '.$person_email."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); } ?> Hi guys, I am thinking of create an free email system by sending an messages using with a username. Would I have to store the messages via in mysql? If I can do that, then I just curious that how would a user delete their messages if their messages is display on php page? What method would I have to use? Hello, I'm trying to create a system where I can monitor where people are at on my website (so I'll be able to see which specific page their on). However, I've ran into a snag, because I have no idea where to start. There isn't an account system used so it has to be based off ip address and I only wanted to display active people within the last 15 minutes. So, I'm assuming this has to be session/cookie based, but I've never had to work with that before. I'm a complete loss and I've tried looking up tutorials online, but I'm not getting any real good results. Could anyone point me in the right direction? Thanks. hello dear PHP-Fans - greetings to you - and a happy new year!! i set up a WAMP-System on my openSuse 11.4 system. In order to learn as much as i can bout PHP i want to do some tests and write some scripts. Well the WAMP is allready up and running. Now i try to give the writing access to the folder mkdir /srv/www/ where the php-scripts should go in... i want to give write permission to all to all files in /srv/www As root I generally: mkdir /srv/www/ chown <webmaster usrername> /srv/www/ /srv/www/ should be readable and traversable by all, but only writeable by it's owner (the user designated as the webmaster.) can i do this like mentioned above,... Love to hear from you greetings db1 i wanting users to be able to update there email address and check to see if the new email already exists. if the email is the same as current email ignore the check. i have no errors showing up but if I enter a email already in the db it still accepts the new email instead of bringing the back the error message. Code: [Select] // email enterd from form // $email=$_POST['email']; $queryuser=mysql_query("SELECT * FROM members WHERE inv='$ivn' ") or die (mysql_error()); while($info = mysql_fetch_array( $queryuser )) { $check=$info['email']; // gets current email // } if($check!=$email){ // if check not equal to $email check the new email address already exists// $queryuser=mysql_query("SELECT * FROM members WHERE email='$email' "); //$result=mysql_query($sql); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error= "0"; header('LOCATION:../pages/myprofile.php?id='.$error.''); } } cheers I have a table in my database named newsletter, with a field named email. Is there a way in php to delete the row with email address field if the email is undeliverable to that email address because it no longer exists? Thank you in advance! Is there anything I should change on this code? I'll use it to send about 20000 emails... I don't like this one, because while sending the emails, the page keep loading... I kind dont "trust" on this script.. index.php Code: [Select] <?php include('config.php'); include('class.phpmailer.php'); include('email.php'); // Get users info $getUser_sql_not_sent = "SELECT * FROM emails WHERE sent = '0'"; $getUser_not_sent = mysql_query($getUser_sql_not_sent); $getUser_num_not_sent = mysql_num_rows($getUser_not_sent); $getUser_sql_sent = "SELECT * FROM emails WHERE sent = '1'"; $getUser_sent = mysql_query($getUser_sql_sent); $getUser_num_sent = mysql_num_rows($getUser_sent); $getUser_sql_all = "SELECT * FROM emails"; $getUser_all = mysql_query($getUser_sql_all); $getUser_num_all = mysql_num_rows($getUser_all); $getUser_sql_accessed = "SELECT * FROM emails WHERE accessed = '1'"; $getUser_accessed = mysql_query($getUser_sql_accessed); $getUser_num_accessed = mysql_num_rows($getUser_accessed); $money = $getUser_num_accessed * 0.20; $money_formated = number_format($money, 2, ',', ''); $x = $getUser_num_sent * 100; $y = $getUser_num_all; $percentage = $x / $y; $percentage_formated = number_format($percentage, 0, '', ''); if ($getUser_num_not_sent == $getUser_num_all) { echo '<form action = "send.php" method = "post">'; echo '<strong>Assunto do Email</strong><br />'; echo $emailSubject; echo '<br />'; echo '<strong>Corpo do Email</strong><br />'; echo $emailBody; echo '<br /><br />'; echo '<input name = "send" type = "submit" value = "Enviar Emails" />'; echo '</form>'; } else { echo "Foram enviados " . $percentage_formated . "&#37; dos emails. " . $getUser_num_accessed . " acessaram o site, bonificação de R&#36; " . $money_formated . " para o Claudius Ibn."; } ?> Code: [Select] <?php include('config.php'); include('class.phpmailer.php'); include('email.php'); echo 'Os emails estao sendo enviados, voce pode sair do site que o processo continuara mesmo assim.'; // Get users info $getUser_sql_not_sent = "SELECT * FROM emails WHERE sent = '0'"; $getUser_not_sent = mysql_query($getUser_sql_not_sent); $getUser_num_not_sent = mysql_num_rows($getUser_not_sent); $mail = new PHPMailer(); while ($row = mysql_fetch_array($getUser_not_sent)) { // Get the current user's email $emailUser = $row['email']; // Define mail object and mail parameters $mail -> From = 'campainha@ibnshare.com'; $mail -> FromName = 'Campainha'; $mail -> AddAddress($emailUser); $mail -> Subject = $emailSubject; $mail -> Body = $emailBody; // Send and verify if(!$mail -> Send()) { echo 'Erro: '. $mail -> ErrorInfo; } else { mysql_query("UPDATE emails SET sent = '1' WHERE email = '$emailUser'"); } sleep(30); } ?> Hey guys so I'm working on creating my own CMS for my website and one of the features I am having trouble with is creating the script to mail a newsletter to everyone in the database. I thought it would be simple enough but I cant seem to figure it out. When I run the code below everything seems to work however only the first email in the database actually receives an email. I think it might be something with my while() loop but I'm not sure. Any help would be greatly appreciated. Code: [Select] $subject = $_POST['subject']; $message = nl2br($_POST['message']); // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: B.net' . "\r\n"; // Connect to database // requires Global Functions ratings_db_connect(); // Finds the number of verified subscriptions $qry ="SELECT * FROM subscriptions WHERE verified ='yes'"; $result = mysql_query($qry); while ($email = mysql_fetch_array($result)){ $email = $email['email']; mail ($email,$subject,$message,$headers); } I have jobs portal where registered users posts new jobs searches
This weekly newsletter will send all the jobs posted in the site (in a week) to the registered users but in a more personalized way: For example, posted jobs looking for designers should be sent to users registered as designers.
what is the best way to do this? any recommendations? Thanks in advance.
Hello all! I am trying to send mail using the "Mail.php" function but I cant figure out whats going wrong. The insert function works in the database but not the sending mail function. Please let point me in the right direction, thanks for your help in advance!
<?php if(isset($_POST)){ //If the post is not empty, continue if(!empty($_POST)) { include_once 'includes.php'; require_once 'Mail.php'; $from = "Name <email@foobar.com>"; $subject = $_POST['subject']; $text = $_POST['newsletterBody']; $host = "host"; $port = "port"; $username = "EMAILUSERNAME"; $password = "EMAILPASSWORD"; echo "Subject: " . $subject; echo "<br />Body: " . $text; echo "<br />Host: " . $host; echo "<br />Port: " . $port . "<br />"; $sql = 'INSERT INTO newsletter_log (date,title,body) VALUES (:time,:subject,:body)'; $params = array( ':subject' => $subject, ':body' => $text, ':time' => time()); $poststmt = $DBH->prepare($sql); $poststmt->execute($params); if($poststmt) { echo "Saved to the database."; } else { echo "Not saved."; } $sqlSubUsers = 'SELECT * FROM test_newsletter WHERE newsletter_id = 1'; $newsletterStmt = $DBH->prepare($sqlSubUsers); $newsletterStmt->execute(); $userIds = $newsletterStmt->fetch(PDO::FETCH_ASSOC); echo $userIds; foreach ($userIds as $row){ $getUserEmailSql = 'SELECT email_addr FROM newsletter_emails WHERE id =' . $row['people_id']; $getUserEmailStmt = $DBH->prepare($getUserEmailSql); $getUserEmailStmt->execute(); $userEmail = "<" . $getUserEmailStmt->fetch(PDO::FETCH_COLUMN,0) . ">"; $userEmail->closeCursor(); $html = "<html><body>" . $text . "</html></body>"; $headers = array ('From' => $from, 'To' => $userEmail, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $html); echo $userEmail; if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } } echo 'Newsletter Sent.'; } else { echo '<h3>No newsletter was sent.</h3>'; } } ?>I have removed the emails, host, port, username and password along with in other information I did not think I should send over. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=313625.0 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&#058;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&#058;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(); ?> Hi, I am using the phpmailer class and a little script I found online, I have a form with a textarea called "plain" which submits and takes the action through to this page: Code: [Select] <?php #include PHPMailer class and database connection include("class.phpmailer.php"); include("connect.php"); #remove slashes from content $plain = stripslashes($_POST["plain"]); #initiate PHPMailer class $mail = new PHPMailer(); #set the from e-mail address $mail->From = "email@email.com"; #set the from name $mail->FromName = "myname"; #the subject of the email $mail->Subject = "Our Newsletter"; #the HTML content of the email $mail->Body = $plain; #loop through e-mail addresses $query = "SELECT email FROM member"; $result = mysql_db_query ("define_pete", $query); while ($myrow = mysql_fetch_array($result)){ #add subscribers address as the recipient $mail->AddAddress($myrow["fldEmail"]); #sends the newsletter $mail->Send(); #clears the recipient address $mail->ClearAddresses(); } ?> It gives no errors and goes through, yet it definitely sends no emails out, I have made sure the emails are correct in the field email in the table member but it is, anyone got any clue what is going wrong? Appreciated I am working on building a newsletter with PHP. I have gotten everything to work but the pulling of the email address.
First is the sendnl.php file
<?php require("../PHPMailer/class.phpmailer.php"); include 'includes.php'; $mail = new PHPMailer; $subject = $_POST['subject']; $text = $_POST['newsletterBody']; $mail->IsSMTP(); $mail->Host = 'localhost'; $mail->Port = '465'; $mail->SMTPAuth = true; $mail->Username = '******USERNAME'; $mail->Password = '*****PASSWORD'; $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; $mail->From = '***EMAIL'; $mail->FromName = '****FROMNAME'; $email = getEmail("73", $DBH); foreach ($email as $nlEmail) { $addEmail = $nlEmail->email; $mail->AddAddress($addEmail); $DBH = null; $addEmail = ""; } $mail->AddReplyTo('******EMAIL', '*****EMAILNAME'); $mail->WordWrap = 50; $mail->IsHTML(true); $mail->Subject = $subject; $mail->Body = $text; $mail->AltBody = $text; if(!$mail->Send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } echo 'Message has been sent'; ?>Next is part of the includes file going over the function and class function getEmail($inId, $DBH) { if (!empty($inId)) { $blogstmt = $DBH->prepare("SELECT email_addr FROM newsletter_emails WHERE id = :userId"); $blogstmt->bindParam(":userId", $inId, PDO::PARAM_STR, 6); $blogstmt->execute(); } else { $blogstmt = $DBH->prepare("SELECT * FROM newsletter_emails"); $blogstmt->execute(); } $postArray = array(); $results = $blogstmt->fetchAll(PDO::FETCH_ASSOC); foreach($results as $row){ $myPost = new nlEmails($row["id"], $row['email'], $DBH); array_push($postArray, $myPost); } return $postArray; $DBH = null; } class nlEmails { public $id; public $email; function __construct($inId=null, $inEmail=null, $DBH) { if(!empty($inId)) { $this->id = $inId; } if(!empty($inEmail)) { $this->email = $inEmail; } } }It gives me an Unidentified index error message for the "id" and "email" used in the getEmail function. Thanks for any help or pointers. Edited by travisco87, 08 October 2014 - 03:33 PM. Hello, I am working with a SMTP class to send an email. It's all working perfectly fine, but when the email is received (sent from the online form), and I open my email and click reply, there are two email addresses. The correct one (which I entered when I sent the email), and my ftp username for the site?? I've got three files that could effect this, but I was unable to locate any problems: mailer.php ( smtp send mail class) mail.php ( submission data: title, subject, etc. ) contact_form.php ( form for submission ) I am only including the file which I think is applicable (mail.php), but let me know if you would also like to see the mailer.php class. Current output: reply-to ftpusername@domainname.com, correct_from_email@fromemail.com mail.php: <?php set_time_limit(120); function sendHTMLmail($from, $to, $subject, $message) { $message = wordwrap($message, 70); // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= "From: $from\r\n"; // Mail it mail($to, $subject, $message, $headers); } function sendHTMLmail2($fromid, $to, $subject, $message) { echo $fromid; echo $to; echo $subject; echo $message; include_once("mailer.php"); $mail = new PHPMailer(); $mail->IsMail(); // SMTP servers $mail->Host = "localhost"; $mail->From = $fromid; $mail->FromName = $fromid; $mail->IsHTML(true); $mail->AddAddress($to, $to); $mail->Subject = $subject; $mail->Body = $message; $mail->AltBody = "Please enable HTML to read this"; $mail->Send(); exit; } function isValidEmail($email) { return eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$", $email); } class smtp_mail { var $host; var $port = 25; var $user; var $pass; var $debug = false; var $conn; var $result_str; var $charset = "utf-8"; var $in; var $from_r; //mail format 0=normal 1=html var $mailformat = 0; function smtp_mail($host, $port, $user, $pass, $debug = false) { $this->host = $host; $this->port = $port; $this->user = base64_encode($user); $this->pass = base64_encode($pass); $this->debug = $debug; $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($this->socket) { $this->result_str = "Create socket:" . socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("Initialize Faild,Check your internet seting,please"); } $this->conn = socket_connect($this->socket, $this->host, $this->port); if ($this->conn) { $this->result_str = "Create SOCKET Connect:" . socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("Initialize Faild,Check your internet seting,please"); } $this->result_str = "Server answer:<font color=#cc0000>" . socket_read($this->socket, 1024) . "</font>"; $this->debug_show($this->result_str); } function debug_show($str) { if ($this->debug) { echo $str . "<p>\r\n"; } } function send($from, $to, $subject, $body) { if ($from == "" || $to == "") { exit("type mail address please"); } if ($subject == "") $sebject = "none title"; if ($body == "") $body = "none content"; $All = "From:$from;\r\n"; $All .= "To:$to;\r\n"; $All .= "Subject:$subject;\r\n"; if ($this->mailformat == 1) { $All .= "Content-Type:text/html;\r\n"; } else { $All .= "Content-Type:text/plain;\r\n"; } $All .= "Charset:" . $this->charset . ";\r\n\r\n"; $All .= " " . $body; $this->in = "EHLO HELO\r\n"; $this->docommand(); $this->in = "AUTH LOGIN\r\n"; $this->docommand(); $this->in = $this->user . "\r\n"; $this->docommand(); $this->in = $this->pass . "\r\n"; $this->docommand(); if (!eregi("235", $this->result_str)) { $this->result_str = "smtp auth faild"; $this->debug_show($this->result_str); return 0; } $this->in = "MAIL FROM: $from\r\n"; $this->docommand(); $this->in = "RCPT TO: $to\r\n"; $this->docommand(); $this->in = "DATA\r\n"; $this->docommand(); $this->in = $All . "\r\n.\r\n"; $this->docommand(); if (!eregi("250", $this->result_str)) { $this->result_str = "Send mail faild!"; $this->debug_show($this->result_str); return 0; } $this->in = "QUIT\r\n"; $this->docommand(); socket_close($this->socket); return 1; } function docommand() { socket_write($this->socket, $this->in, strlen($this->in)); $this->debug_show("Client command:" . $this->in); $this->result_str = "server answer:<font color=#cc0000>" . socket_read($this->socket, 1024) . "</font>"; $this->debug_show($this->result_str); } } ?> |