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

Thread: Sending Email

  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sending Email

    Ok this should be an easy question to answer. I have a domain name www.anova-design.com. I'm very good with web design, but I'm new to php and it's driving me crazy! Haha, anyways I'm trying to send an email using a form. This is what I have so far...

    email.php:

    <form action="send.php" method="post"><table border="1" cellspacing="0" cellpadding="1">
    <tr>
    <td>Name:</td>
    <td><input name="Name" type="text" id="Name"></td>
    </tr>
    <tr>
    <td height="23">Email:</td>
    <td><input name="Email" type="text" id="Email"></td>
    </tr>
    <tr>
    <td height="23">Subject:</td>
    <td><input name="Subject" type="text" id="Subject"></td>
    </tr>
    <tr>
    <td height="23">Comments</td>
    <td><textarea name="textarea" wrap="VIRTUAL"></textarea></td>
    </tr>
    <tr>
    <td height="23"><input name="Submit" type="submit" id="Submit" value="Send"></td>
    <td>&nbsp;</td>
    </tr>
    </table>
    </form>

    send.php:
    <?php
    $to = "soccer022483@comcast.net";
    $name = $_POST['Name'];
    $from = $_POST['Email'];
    $subject = $_POST['Subject'];
    $comment= $_POST['Comments'];
    $message = "$comment \n\n From,\n\n $name \n\n";
    $headers = "From: $from\r\n";

    $success = mail($to, $subject, $message, $headers);
    if ($success)
    echo "The email to $to from $from was successfully sent";
    else
    echo "The Must be an Error on the Page that you have sent us Please go back and Try agian to $to from $from";
    ?>

    Ok those are the two files. When I upload them and go to www.anova-design.com/email.php it comes up fine. When I test it out and try to send the email to my self I never receive it. I know my host is php enabled. Can anyone help me out??

    Austin

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Location
    Birmingham, MI
    Posts
    131
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're only checking if the variable "success" is not null, since its not null, you get the success message, try:

    PHP Code:
    <?php
    $to 
    "soccer022483@comcast.net";
    $name $_POST['Name'];
    $from $_POST['Email'];
    $subject $_POST['Subject'];
    $comment$_POST['Comments'];
    $message "$comment \n\n From,\n\n $name \n\n";
    $headers "From: $from\r\n";

    if (
    $name && $from && subject && comment) { // make sure these fields arent null
    echo "The email to $to from $from was successfully sent";
    mail($to$subject$message$headers);
    } else {
    echo 
    "The Must be an Error on the Page that you have sent us Please go back and Try agian to $to from $from";
    }
    ?>

  • #3
    New Coder
    Join Date
    Jul 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Yeah but...

    Yeah but even with my code it says the mail was successfully sent. I didn't come up with this code I got it off a site somewhere that says it works (who knows). I still should be receiving the email regardless. I don't think it's a problem with the code but maybe my host, or maybe I don't have something set up right, I have no idea.

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by circusbred
    You're only checking if the variable "success" is not null, since its not null, you get the success message,
    actually, that is not correct. Mail returns a boolean (False or True) so his initial

    if ($success)
    echo "The email to $to from $from was successfully sent";

    is just fine.

    Your code on the other hand is buggy and contains the logical error that you would print the message before even executing the mail() ! Your statusmessage doesn't check the outcome of the mail-action.


    soccer022483, try it with another mailadress or else contact your host.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    New Coder
    Join Date
    Jul 2004
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok. Thanks for the help you guys.

    Austin


  •  

    Posting Permissions

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