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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mail function not working

    I can't get my form on this page to actually send email.

    Code:
    <?php
    
    if(($_GET['action'])=='send'){
            $message=$_POST['message'];
            if(($message != "") && ($message != 'Message')){
                    $realname=$_POST['realname'];
                    if($realname!=''){$postrealname='Name: ' . $realname . "\n";};
                    $email=$_POST['email'];
                    if(($email!='') && (ereg('@',$email))) {$postemail='Email: ' . $email . "\n";};
                    $message = stripslashes($message);
    
                    $to=$_POST['to'];
                    if($to=='pastor'){
                            $to='pastor's email address';
                            }
                    elseif($to=='associate'){
                            $to='associate minister's email address';
                            }
                    elseif($to=='youth'){
                            $to='youth minister's email address';
                            }
                    else{
                            $to='my email address';
                            }
                    $subject = "from parklandbaptistchurch.org";
                    $message=$message . "\n" . $postrealname . $postemail;
    
                    $headers = "From: " . $realname . " <" . $email . ">\r\n";
    
                    mail($to, $subject, $message, $headers);
                    echo '<p>Your message has been sent.</p>';
                    }
            }
    else { ?>
    
    <h2>Contact Us</h2>
    
    <p><strong>Parkland Baptist Church</strong><br />
    7206 Shepherdsville Rd., Louisville, Kentucky 40219, United States<br />
    Phone: 502-969-1387<br />
    Fax: 502-969-1388</p>
    
    <form action="contact.html?action=send" method="post">
    <fieldset>
     <legend>E-mail form</legend>
     <label for="name">Name:</label><input type="text" id="name" name="realname" value="Name" onfocus="clearDefault(this)" onblur="insertDefault(this)" class="form" />
     <label for="email">Email:</label><input type="text" id="email" name="email" value="Email Address" onfocus="clearDefault(this)" onblur="insertDefault(this)" class="form" />
     <label for="to">Who would you like to contact?</label><select><option value="pastor">Pastor Tom Curry</option><option value="associate">Associate Minister Todd Beasley</option><option value="youth">Youth Minister Beth Turpin</option><option value="web">Web Developer Chris Huff</option></select>
     <label for="message">Message:</label><textarea id="message" name="message" rows="3" cols="25" onfocus="clearDefault(this)" onblur="insertDefault(this)" class="form">Message</textarea>
     <p><em>* All fields are required</em></p>
     <input type="submit" value="send" class="submit" /> <input type="reset" class="submit" value="clear" />
    </fieldset>
    </form>
    
    <?php } ?>
    Here's my phpinfo if that's helpful. I noticed that I doesn't have a MAIL or _ENV["MAIL"] variable like other domains that I have. Is this the problem? If so, how do I add it?
    Last edited by BroChris; 02-02-2007 at 06:57 PM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,468
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Is your server set-up so that .html file extensions are
    processed as PHP scripts? If not, rename the extension
    to .php and change your <form> line.

  • #3
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    You must also make sure that the smtp server is set up on your web server so that you can actually send mail.

    -Shane

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, html files are parsed for php.

    And yes, it appears that smtp is set up. Any other ideas?
    Last edited by BroChris; 02-02-2007 at 06:32 PM.

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    I get a fatel parse error when testing the code (looking for typo's, syntax errors...) This line is not valid code -
    PHP Code:
    else($to=='web'){ 
    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.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, when I was editing out email addresses I wrote an error into the code. It's fixed now.

    I've verified that this does work on my own local server, but it won't work once I upload it to the web server. What variables on that side of things might be causing this not to work?

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    Check your server error log and/or put the following after your first opening <?php tag -
    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL); 
    This will tell you if the mail(...) function call is failing. Also, it would not hurt to put if(mail(...)){ succeeded.. } else { failed... } conditional logic around the mail(...) function call.
    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.

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    Louisville, KY
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you so much. It's working now. Turning on errors helped me find the problem (I should have done that in the beginning...).


  •  

    Posting Permissions

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