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

Thread: php email

  1. #1
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php email

    trying to write an email script, been banging my head off the wall for hours, can anyone see anything wrong with this?

    PHP Code:

    <?

    $failure 
    0;

    error_reporting(0);

    $errorlist " ";

    if(isset(
    $_POST["Name"]) && $_POST["Name"] !=""
    {
        
    $name $_POST["Name"];
    }

    else
    {
        
    $name "";
        
    $failure 1;
        
    $errorlist .= "A name is required.<br />";
    }

    if(isset(
    $_POST["Subject"]) && $_POST["Subject"] !="")
    {
        
    $subject $_POST["Subject"];
    }

    else
    {
        
    $subject "";
        
    $failure 1;
        
    $errorlist .= "Please provide a subject for this query so we can send it to the relevant department. <br />";
    }

    if(isset(
    $_POST["Where"]) && $_POST["Where"] !="")
    {
        
    $where $_POST["Where"];
    }

    else
    {
        
    $where "";
        
    $failure 1;
        
    $errorlist .= "Please state where you found us (yell.com, google etc).<br />";
    }

    if(isset(
    $_POST["Email"]) & $_POST["Email"] !="")
    {
        
    $email $_POST["Email"];
        list(
    $username,$domain) = split("@",$email);
    }

    else
    {
        
    $email "";
    }

    if(
    $domain == "")
    {
        
    $failure 1;
        
    $errorlist .= "Please provide a valid email address.<br />";
    }

    if(isset(
    $_POST["Content"])  && $_POST["Content"] !="")
    {
        
    $content $_POST["Content"];
    }

    else
    {
        
    $content "";
        
    $failure 1;
        
    $errorlist .= "Please provide some comments.<br />";
    }

    if(
    $failure !=0)
    {

        if(isset(
    $_POST["Posted"]))
        {
            echo(
    "<p style='color:red;'>");
            echo(
    $errorlist);
            echo(
    "</p>");
        }
    ?>

    <form action="" method="post" class="contact">

    <label for="name">Name:</label>

    <input type="text" name="Name" id="name" value="<?=$name?>" />

    <label for="email">E-mail:</label>

    <input type="text" name="Email" id="email" value="<?=$email?>" />

    <label for="subject">Subject:</label>

    <input type="text" name="Subject" id="subject" value="<?=$subject?>" />

    <label for="where">Where did you hear about us:</label>

    <input type="text" name="Where" id="where" value="<?=$where?>" />

    <label for="Content" style="margin-left:-120px;">Comments:</label>

    <input type="hidden" name="Posted" ID="posted" value="1">

    <textarea name="Content" ID="Content" style="width:450px; height:150px; margin-top:15px; _margin-top:-15px;">
    <?=$content?>
    </textarea>

    <input type="submit" value="Send" style="width:70px; margin-top:15px; margin-left:252px;" />

    </form>
    <?
    }

    else
    {
    echo(
    "<P>Thank you $name for your message. We will get back to you ASAP.</P>");

    $msg            "<table border=0 style='border:1px solid #000000;'>";
    $msg            .= "<tr><td><img src='http://astra.streamlinenettrial.co.uk/images/header.jpg' style='width:750px; height:100px;' /></td></tr>";
    $msg            .= "<tr><td>";

    $msg            .= "<p><strong>From:</strong> $name</p>";
    $msg            .= "<p><strong>Subject:</strong> $subject</p>;";
    $msg            .= "<p><strong>Found us at:</strong> $where</p>;";
    $msg            .= "<p><strong>Comments:</strong><br /><br /> $content</p>;";

    $msg            .= "</td></tr>";
    $msg            .= "</table>";

    $recipient "ttpparker@talk21.com";


    // To send HTML mail, the Content-type header must be set
    $headers  "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=ISO-8859-1\r\n";

    // Additional headers
    $headers .= "From: TIM ParMEN <ttpparker@talk21.com>\r\n";
    $headers .= "Reply-To: $email";

    echo(
    $subject); 
    echo(
    $recipient);
    echo(
    $headers);


    mail($recipient$subject$msg$headers);
    }
    ?>

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,147
    Thanks
    2
    Thanked 333 Times in 325 Posts
    And what it is doing or not doing so that we know what we should be looking at to help you with? There could literally be a hundred different things wrong. You need to narrow it down a bit.
    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.

  • #3
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    just not sending the email, doesnt return an error (even if i turn errors on).

  • #4
    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
    Wow that was helpful.

    Does the mail() function return true or false? I see you've added echo statements to see what's in your mail variables. And?

    Add print_r($_POST) to the top of the script and see what that tells you.

  • #5
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mail doesnt return anything, the echo of the variables print out what i expect them to.

    print_r($_POST) returns all the form fields and it all seems in order.

    Im not sure what it is you need to know, anything in paticular?

  • #6
    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
    From the manual:
    Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

  • #7
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    im pretty new to php, how would i get to output whether its true or false?

  • #8
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    PHP Code:
    if (mail($recipient$subject$msg$headers)) {
        echo 
    Mailed succesfully!";
    } else {
        echo "
    A problem occured while attempting to mail.";



  •  

    Posting Permissions

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