[SOLVED] email question

This is a discussion on "[SOLVED] email question" within the PHP Forum section. This forum, and the thread "[SOLVED] email question are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1  
Old Oct 3rd, 2007, 05:15
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] email question

hi,

I have just created a email blast in the php along with a table subscribers in the photos database, and tested at http://localhost:8888/24/emailblast.php. Not sure why it didn't show me the result after I sendt the testing News letter to those email records which has been inserted into database table 'subscribers' from database 'photos'?

Any inputs will be great appreciated!!!

PHP: Select all

<?php
if($_POST[op] !="send"){
    
//haven't seen the form, so show it
    
echo "
        <html>
            <head>
            <title>Sending a Email blast</title>
            </head>
            <body>
            <h1>Send a News Letter</h1>
            <form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
                <p><b>Subject:</b><br>
                <input type=\"text\" name=\"subject\" size=30></p>
                <p><b>Mail body:</b><br>
                <textarea name=\"message\" cols=50 rows=10 wrap=virtual></textarea>
                <input type=\"hidden\" name=\"op\" vaule=\"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: emailblast.php");
        exit;
    }
    
//connect to database
    
$conn mysql_connect('localhost','root','root');
    
mysl_select_db('photos') or die(mysql_error());
    
    
//get emails from subscriber list
    
$sql "select email from subscribers";
    
$result mysql_query($sql) or die(mysql_error());
    
    
//create a from: mailheader
    
$headers "From: Your Mailing List <you@yourdomain.com>";
    
//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);
        echo 
"newsletter sent to: $email<br>";
    }
}

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Oct 3rd, 2007, 06:08
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: email question

Hi,

In your form, you have mispelt "value" in the hidden element named "op", this would mean the $_POST['op'] will never = 'send';

Cheers,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Oct 3rd, 2007, 08:59
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: email question

You can actually do this with a bit less code. The hidden value is unnecessary because you need a subject to send an email anyway so you can just check to see if the subject is set. I'm not sure where this script is going to be used, but its always a good idea to validate user input.

I also cleaned up you code a bit: single quotes and the "." concatenation operator are always much faster than double quotes. If you have a double-quoted string, then the PHP interpreter has to check the whole string for inline variables. Also, if you use single quotes, then you don't have to escape the double quotes in your HTML code....

So, check this out. I know this may seem a bit trivial for such a small project, but if you write clean, efficient code from the beginning on, then when you have a larger project, you will notice the difference:

PHP: Select all

<?php
if(isset($_POST['subject'])&&$_POST['subject']!=''){
    
//want to send form, so check for required fields
    
if(($_POST[subject] =="") || ($_POST[message] == "")){
        
header('Location: emailblast.php');
        exit;
    }
    
//connect to database
    
$conn mysql_connect('localhost','root','root');
    
mysl_select_db('photos') or die(mysql_error());
    
    
//get emails from subscriber list
    
$sql 'select email from subscribers';
    
$result mysql_query($sql) or die(mysql_error());
    
    
//create a from: mailheader
    
$headers 'From: Your Mailing List <you@yourdomain.com>';
    
//loop through results and send mail
    
while($row mysql_fetch_array($result)){
        
set_time_limit(0);
        
$email $row['email'];
        
mail($emailstripslashes($_POST[subject]),stripslashes($_POST[message]), $headers);
        echo 
'newsletter sent to: '.$email.'<br>';
    }
} else { 
//haven't seen the form, so show it
?>
<html>
    <head>
    <title>Sending a Email blast</title>
    </head>
    <body>
    <h1>Send a News Letter</h1>
    <form method="post" action="<?php echo $_SERVER[PHP_SELF]; ?>">
        <p><b>Subject:</b><br>
        <input type="text" name="subject" size="30"></p>
        <p><b>Mail body:</b><br>
        <textarea name="message" cols="50" rows="10" wrap="virtual"></textarea>
        <p><input type="submit" name="submit" value="Send It"></p>
    </form>
    </body>
</html>
<?php ?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old Oct 3rd, 2007, 15:38
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: email question

PHP: Select all

} else { //haven't seen the form, so show it
?>
<html>
    <head>
    <title>Sending a Email blast</title>
    </head>
    <body>
    <h1>Send a News Letter</h1>
    <form method="post" action="<?php echo $_SERVER[PHP_SELF]; ?>">
        <p><b>Subject:</b><br>
        <input type="text" name="subject" size="30"></p>
        <p><b>Mail body:</b><br>
        <textarea name="message" cols="50" rows="10" wrap="virtual"></textarea>
        <p><input type="submit" name="submit" value="Send It"></p>
    </form>
    </body>
</html>
<?php ?>
[/quote]
Thanks for that Jan.
I didn't know you could do it like that,
saves adding slashes to everything!
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #5  
Old Oct 3rd, 2007, 17:36
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: email question

I'm not sure if ending the PHP tags is more efficient than using echo, but for readability its much nicer.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #6  
Old Oct 3rd, 2007, 18:54
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Re: email question

Great help, I am using your codes which is much less codes and easy to read! Much appreciated!!
Do I need to modify the php.ini file? Because when I click on send. I got this


Fatal error: Call to undefined function mysl_select_db() in /Applications/MAMP/htdocs/24/emailblast.php on line 8

Not sure what is wrong with "mysql_select_db('photos')"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #7  
Old Oct 3rd, 2007, 18:59
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: email question

yes you need to enable the mysql extension
do you want a copy of my php.ini file?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #8  
Old Oct 3rd, 2007, 22:17
Junior Member
Join Date: Nov 2006
Location: us
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
remote emailblast error

Hi alexgeek,
Yes, I'd like to have your php.ini file.
After I sumbitted the emailblast.php at http://www.sandragreen.com/emailblast.php I've got this errors:
Fatal error: Call to undefined function: mysl_select_db() in /home/sandr10/public_html/emailblast.php on line 8,
after I uploaded emailblast.php to the remote server.
Quote:
"Yes you need to enable the mysql extension
do you want a copy of my php.ini file?"

I heartfully appreciated your help!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #9  
Old Oct 3rd, 2007, 22:31
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: remote emailblast error

  • Rename to php.ini
  • replace it with yours
  • restart web service (apache)
Attached Files
File Type: txt php.ini.txt (45.3 KB, 3 views)
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
email security question... MikeTheVike Web Page Design 3 May 6th, 2008 20:16
[SOLVED] Form to email script with checkboxes Posie PHP Forum 4 Dec 10th, 2007 03:54
[SOLVED] sending email once form submitted Emzi PHP Forum 5 Nov 21st, 2007 14:25
[SOLVED] Form Submit To Email longstand PHP Forum 17 Nov 13th, 2007 13:16
[SOLVED] Form to email with checkbox itsdesign PHP Forum 4 Oct 29th, 2007 00:57


All times are GMT. The time now is 22:20.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42