twilitegxa Posted August 26, 2008 Share Posted August 26, 2008 I'm trying to use a mailing script for mailing out a newsletters, but I'm using WampServer and it doesn't have a mail server. Does anyone know any extremely easy to install mail server for Windows? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 First make sure that your ISP will even let you send e-mail from your computer. I doubt they will, honestly. >_> Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 Why wouldn't they let me? They don't have a built in mail server for me to use, but why couldn't I download one to use? How do other people send out newsletters using PHP script? Quote Link to comment Share on other sites More sharing options...
aebstract Posted September 19, 2008 Share Posted September 19, 2008 mail(); http://us.php.net/mail Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 That link you sent me, I don't completely understand it. Would I just use the code at the end of the page? Quote Link to comment Share on other sites More sharing options...
aebstract Posted September 19, 2008 Share Posted September 19, 2008 mail($recipient, $subject, $mail_body, $header); //mail command Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 19, 2008 Share Posted September 19, 2008 You need a properly configured public mail server in order to get any other mail server to accept emails from your mail server. A public mail server is one that has a domain name associated with it and a DNS server that is configured to resolve DNS requests for the domain and the mail server's DNS records. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 If I used this code: mail($recipient, $subject, $mail_body, $header); //mail command How do I name these varaibles? Do I just do it like this: $subject = "Newsletter #1"; $mail_body = "This is our newsletter...blah blah blah..." How do I pull the $recipients from my table in my database? And what would I put for $header? Quote Link to comment Share on other sites More sharing options...
corbin Posted September 19, 2008 Share Posted September 19, 2008 I use hMailServer when under Windows. Then again, I had to find something quickly, so I never really looked into much else since it worked for my needs and was free. Quote Link to comment Share on other sites More sharing options...
Stooney Posted September 19, 2008 Share Posted September 19, 2008 There's also mercury mail. I never figured it out but it's a free option. As for mail() [code] <?php $to='email@place.com'; $subject='message for you'; $message='message'; $from='From: me@email.com'; mail($to, $subject, $message, $from); ?> I haven't used it, but cURL has a better solution for mass emails (newsletters etc). Another option would be using sockets to connect to an smtp server you have access to and sending mail out that way.[/code] Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 In your example, can you set the $to variable to pull the e-mail addresses from a table in a database? Quote Link to comment Share on other sites More sharing options...
Stooney Posted September 19, 2008 Share Posted September 19, 2008 You can only mail to 1 person per mail() if that makes sense. So if you have 10 people you wish to email, you need to loop it 10 times. <?php $from='From: me@email.com'; $subject='Subject here'; $message='newsletter'; $emails=mysql_query("SELECT email FROM users"); if(mysql_num_rows($emails)>0){ while($row=mysql_fetch_array($emails)){ mail($row['email'], $subject, $message, $from); } } else{ //No email addresses found } ?> Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 So this code would loop until it returned no more e-mails in my table, correct? Quote Link to comment Share on other sites More sharing options...
Stooney Posted September 20, 2008 Share Posted September 20, 2008 Yep, it will send an email to each email address pulled out of the database. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 20, 2008 Author Share Posted September 20, 2008 I there a way I can use this scriptthat you suggested: <?php $from='From: me@email.com'; $subject='Subject here'; $message='newsletter'; $emails=mysql_query("SELECT email FROM users"); if(mysql_num_rows($emails)>0){ while($row=mysql_fetch_array($emails)){ mail($row['email'], $subject, $message, $from); } } else{ //No email addresses found } ?> with my pre-existing code? I have a form that is supposed to take the information I put in and send it to the e-mail addresses in my table from my database, but it doesn't work, apparently because I don't have a mail server on my web server. Here is the script for it below: <?php //Access Tracking Snippet //set up static variables $page_title = "sendmymail.php"; $user_agent = getenv("HTTP_USER_AGENT"); $date_accessed = date("Y-m-d"); //connect to server and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); $db = mysql_select_db("smrpg", $conn) or die(mysql_error()); //create and issue query $sql = "insert into access_tracker values ('', '$page_title', '$user_agent', '$date_accessed')"; mysql_query($sql,$conn); ?> <?php if ($_POST[op] != "send") { //haven't seen the form, so show it print " <HTML> <HEAD> <TITLE>Send A Newsletter</TITLE> </HEAD> <BODY> <h1>Send A Newsletter</h1> <form method=\"post\" action=\"$_SERVER[php_SELF]\"> <p><strong>Subject:</strong><br /> <input type=\"text\" name=\"subject\" size=30></p> <p><strong>Mail Body:</strong><br /> <textarea name=\"message\" cols=50 rows=10 wrap=virtual></textarea> <input type=\"hidden\" name=\"op\" value=\"send\"> <p><input type=\"submit\" name=\"submit\" value=\"Send It\"></p> </form> </body> </html>"; } else if ($_POST[op] == "send") { //want to send form; so check for required fields if (($_POST[subject] =="") || ($_POST[message] == "")) { header("Location: sendmymail.php"); exit; } //connect to database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$conn) or doe(mysql_error()); //get emails from subscribers list $sql = "select email from subscribers"; $result = mysql_query($sql,$conn) or die(mysql_error()); //create a From: mailheader $headers = "From: Your Mailing List <twilitegxa@aol.com\n"; //loop through results and send mail while ($row = mysql_fetch_array($result)) { set_time_limit(0); $email = $row['email']; mail("email", stripslashes($_POST[subject]), stripslashes($_POST[message]), $headers); print "newsletter sent to $email<br />"; } } ?> Can someone tell me how I can alter this code to work with the suggested code of using the mail function? Quote Link to comment Share on other sites More sharing options...
Stooney Posted September 21, 2008 Share Posted September 21, 2008 The mail function requires a working smtp server. I think you can use someone elses by editing php.ini (never needed to so I haven't looked). Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 21, 2008 Author Share Posted September 21, 2008 That's what I thought. If anyone knows how I need to configure the php.ini file, please let me know! I think I just need to change the port maybe and the smtp probably. Any help would be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.