Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder FWDrew's Avatar
    Join Date
    Apr 2008
    Location
    Missouri
    Posts
    380
    Thanks
    38
    Thanked 45 Times in 43 Posts

    php mail problem

    Hi everyone,

    Im having a small issue with what should be a simple mailing script. Here is the relevant code, that is returning a 500 server error when submitted:

    Form:
    Code:
    <form action="send.php" method="post">
    		<p>Subject:</p>
    		<p><input type="text" name="subject" /></p>
    		<p>Mail Body:</p>
    		<p><textarea rows="10" cols="40" name="body"></textarea></p>
    		<p><input type="submit" name="submitMail" value="Send" /></p>
    		</form>
    send.php
    PHP Code:
    <?php require('conn.php');?>
    <?php
    if($_SESSION['loggedIn'] != 'LOGGEDIN') {
        
    header('Location:index.php');
    }
    elseif(
    $_POST['submitMail'] && !empty($_POST['subject']) && !empty($_POST['body'])) {
        
    $subject strip_tags($_POST['subject']);
        
    $body strip_tags($_POST['body'], '<p><a><b><i><quote>');
        
    $mailHeaders 'Email Newsletter';
        
    //Setup query 
        
    $result mysql_query("SELECT email FROM subscribers") or die(mysql_error());
        while(
    mysql_fetch_array($result)){
            
    $email $row['email'];
            
    mail($email$subject$body$mailHeaders);
            echo 
    "<p>Email sent to the address of " .$row['email']. ".</p>";
        }
        
    mysql_free_result($result);
        
    mysql_close($connection);
    }
    else {
        
    header('Location:index.php');
    }
    ?>
    in case you need it here is conn.php but I am not getting any mysql errors:
    PHP Code:
    <?php
    session_start
    ();
    $host "xxxxxxxxxx";
    $user "xxxxxxxxxx";
    $pass "xxxxxxxxxx";
    $db "xxxxxxxxx";
    $connection mysql_connect($host$user$pass) or die ("Unable to connect to database!");
    mysql_select_db($db) or die ("Unable to select database!"); 
    ?>
    There are no reasons given with the 500 server error, just to contact the server administrator, any ideas?

    Thanks much,

    Drew
    Last edited by FWDrew; 12-14-2008 at 01:32 AM.
    Dev-Tips.com || Employee at the Envato Network || My Portfolio

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    The posted code does not generate a fatal parse error (tested), so it is likely that you have a fatal runtime error. Add the following two lines immediately after your first opening <?php tag, before the require() statement -

    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL); 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    FWDrew (12-14-2008)

  • #3
    Regular Coder FWDrew's Avatar
    Join Date
    Apr 2008
    Location
    Missouri
    Posts
    380
    Thanks
    38
    Thanked 45 Times in 43 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    The posted code does not generate a fatal parse error (tested), so it is likely that you have a fatal runtime error. Add the following two lines immediately after your first opening <?php tag, before the require() statement -

    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL); 
    Updated code:
    PHP Code:
    <?php ini_set ("display_errors""1"); error_reporting(E_ALL);require('conn.php');?>
    <?php
    if($_SESSION['loggedIn'] != 'LOGGEDIN') {
        
    header('Location:index.php');
    }
    elseif(
    $_POST['submitMail'] && !empty($_POST['subject']) && !empty($_POST['body'])) {
        
    $subject strip_tags($_POST['subject']);
        
    $body strip_tags($_POST['body'], '<p><a><b><i><quote>');
        
    $mailHeaders 'Email Newsletter from Lifecoach Sam Douglass';
        
    //Setup query 
        
    $result mysql_query("SELECT email FROM subscribers") or die(mysql_error());
        while(
    mysql_fetch_array($result)){
            
    $email $row['email'];
            
    mail($email$subject$body$mailHeaders);
            echo 
    "<p>Email sent to the address of " .$email".</p>";
        }
        
    mysql_free_result($result);
        
    mysql_close($connection);
    }
    else {
        
    header('Location:index.php');
    }
    ?>
    Is now generating this result:
    Code:
    Notice: Undefined variable: row in xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx on line 13
    No recipient addresses found in header
    
    Email sent to the address of .
    repeats this error 4 times (4 rows in my db). I double check the email field for spelling and to make sure it isnt null and they are all filled and spelled correctly. I cant see what im doing wrong with $row['email'] which is what seems to be the error.

    Thanks for helping me find the error messages, I'm still learning php, any advice now?

    Drew
    Last edited by FWDrew; 12-14-2008 at 01:14 AM. Reason: removed root url
    Dev-Tips.com || Employee at the Envato Network || My Portfolio

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    This line -
    PHP Code:
        while(mysql_fetch_array($result)){ 
    should be -

    PHP Code:
        while($row mysql_fetch_array($result)){ 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    FWDrew (12-14-2008)

  • #5
    Regular Coder FWDrew's Avatar
    Join Date
    Apr 2008
    Location
    Missouri
    Posts
    380
    Thanks
    38
    Thanked 45 Times in 43 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    This line -
    PHP Code:
        while(mysql_fetch_array($result)){ 
    should be -

    PHP Code:
        while($row mysql_fetch_array($result)){ 
    Problem solved, thank you very much

    I knew it had to be missing something simple. Appreciate all the help.

    Drew
    Dev-Tips.com || Employee at the Envato Network || My Portfolio


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •