Newbie: Creating a simple php form email, how?

Discussion in 'Programming/Scripts' started by mancho, Jun 23, 2006.

  1. mancho

    mancho New Member

    Sorry if answered, I couldn't find it.

    I need to create a simple "send form" that processes an email (its sent to a remote listserv).

    I couldn't get it to work with this:

    <?php
    $to = "listserv-on@mail.baskins.com";
    $subject = "Baskins Email Signup";
    $from = "txtEmail";
    if (mail($to, $subject, $from)) {
    echo("<p>Message successfully sent!</p>");
    } else {
    echo("<p>Message delivery failed...</p>");
    }
    ?>

    What am I doing wrong? THe form is here: http://www.baskins.com/email_sign_up.html

    and posts to:
    http://www.baskins.com/emailprocess.php

    thanks for any assistance. I'm using ISPConfig and I LOVE IT!

    mancho
     
  2. geek.de.nz

    geek.de.nz New Member

    Maybe you don't have 'register_globals = On' in your php.ini, which would make this not work.

    However, you can access form variables with
    Code:
    $txtEmail = $_GET['txtEmail'];
    // or
    $txtEmail = $_POST['txtEmail'];
    
    depending on the method of the form (default GET). You should use POST for a lot of data, so e.g. if you're sending a text-area values.

    The mail syntax looks right for me.
     
  3. falko

    falko Super Moderator

  4. themachine

    themachine HowtoForge Supporter

    Yes, Falko is right... the following is the basic usage of mail():

    Code:
    <?php
    
            $my_addy = "user@domain.com";
            $to_addy = "otheruser@otherdomain.com";
            $subject = "Test Subject";
            $message = "Test Message";
    
            $headers = "From: $my_addy \r\n";
            $headers .= "Reply-To: $my_addy \r\n";
            $headers .= "Return-Path: $my_addy \r\n";
    
            mail ($to_addy,$subject,$message,$headers);
    
    ?>
    

    If you wanted to check the return of mail(), you could make it:

    Code:
    ...
    if(mail($to_addy,$subject,$message,$headers)) {
            print "Mail sent OK";
    } else {
            print "Mail did not send properly";
    }
    ...
    

    But this is only checking whether "mail()" returned without error.... it has nothing to do with whether the email got anywhere successfullly.
     

Share This Page