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
    New Coder
    Join Date
    Jul 2009
    Location
    USA
    Posts
    24
    Thanks
    13
    Thanked 0 Times in 0 Posts

    "Simple Contact Form" PHP not sending email

    Hello+
    I have attempted to write a simple PHP script to send the contact information to a specific email address. Everything seems to be working fine, except the email is not reaching me. I'm not certain what is going wrong - can anyone help? The PHP code is below:

    PHP Code:
    <?php

    /* subject and email variables */

        
    $emailSubject 'Contact From Website!';
        
    $webMaster 'nomad654321@earthlink.net';
        
    /* gathering data variables */

        
    $emailField $_POST['email'];
        
    $nameField $_POST['cname'];
        
    $phoneField $_POST['phone'];
        
    $interestedField $_POST['interested'];
        
    $artworkField $_POST['artwork'];
        
    $commentsField $_POST['comments'];
        
        
    $body = <<<EOD
    <br><hr><br>
    Email: $email <br>
    Name: $cname <br>
    Phone Number: $phone <br>
    Interested in: $interested <br>
    Artwork: $artwork <br>
    Comments: $comments <br>
    EOD;

        
    $headers "From: $email\r\n";
        
    $headers .= "Content-type: text/html\r\n";
        
    $success mail($webMaster$emailSubject$body$headers);
        
    /* results rendered as HTML */

        
    $theResults = <<<EOD
    <html>
    <head>
    <title>Photography by Lynn Santus</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    <!--
    body {
        font-family: "Times New Roman", Times, serif;
        font-size: 18px;
        font-style: normal;
        line-height: normal;
        font-weight: normal;
        color: #330099;
        text-decoration: none;
        background-image: url(images/greengrunge10.png);
        text-align: center;
    }
    -->
    </style>
    </head>

    <div>
      <div align="center">
        <p><img src="images/lynnbanner.png" alt="Photography by Lynn Santus" width="801" height="150" border="0" usemap="#Map">
    <map name="Map"><area shape="rect" coords="84,3,603,154" href="index.html" alt="Link to Home Page">
    </map></p>
        <p>Thank you for your interest! Your email will be answered very soon!</p>
        <p>Click <a href="index.html">here</a> to return to the Home Page. </p>
      </div>
    </div>
    </body>
    </html>
    EOD;
    echo 
    "$theResults";

    ?>
    Thank you for any guidance offered...

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Two things-- Turn on full error reporting:

    PHP Code:
    error_reporting(E_ALL);
    ini_set("display_errors"1); 
    And check the success of the mail() function-- you assign the result to variable $success but then you don't check it.

    PHP Code:
    if (!$success) {
        die(
    "error sending email!");

    If the mail() function fails check your PHP error log.

    If all of that doesn't get you anywhere, tell us what kind of PHP install you are using and dump the contents of your phpinfo() here.

  • Users who have thanked Fumigator for this post:

    Gabby7 (09-02-2009)

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I also suggest removing your actual email address from your post or you will soon start to get spammed.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Gabby7 (09-02-2009)

  • #4
    Regular Coder ajetrumpet's Avatar
    Join Date
    Jul 2009
    Location
    Iowa City, IA
    Posts
    407
    Thanks
    44
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Fumigator View Post
    And check the success of the mail() function-- you assign the result to variable $success but then you don't check it.

    PHP Code:
    if (!$success) {
        die(
    "error sending email!");

    If the mail() function fails check your PHP error log.
    you may also want to use your own logs. i do for my website. when i do batch mailings, i write the results to a log then check it when i'm done to see if anything failed in case i need to resend some. it might be of use to you.
    PHP Code:
    if (!$success) {
       
    $logline "delivery failed...|\r\n"; }
    else { 
    $logline "delivery successful!|\r\n"; }

    $file = @fopen("mylogfile""a");
    fputs($file$logline );
    fclose($file); 

  • Users who have thanked ajetrumpet for this post:

    Gabby7 (09-02-2009)

  • #5
    New Coder
    Join Date
    Jul 2009
    Location
    USA
    Posts
    24
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Thank you, everyone! I will do as you suggest and if it doesn't work, then I will re-post. Thank you.


  •  

    Posting Permissions

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