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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    New Coder
    Join Date
    Dec 2004
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Email form script

    I've been working on a email script all day now with no such luck. I thought this would be very easy, but I guess not. None of the email scripts I found seem to work the way I want. I have the form page up fine. It's the action that I'm having trouble with. I don't want the action to be simply mailto:blah@blah.com. Does anyone have a good php script I could use?

    Thanks.

  • #2
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Have you tried PHPMailer?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #3
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just do something very simple like this...

    Code:
    <?php
    $to = "email@email.com";
    $subject = "Message from Contact Form";
    
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    $email = $_POST['email'];
    $web = $_POST['web'];
    $msg = $_POST['msg'];
    
    $body = "Sender: " . $fname . " " . $lname . "\n\nEmail: " . $email . "\n\nWebsite: " . $web . "\n\nMessage:\n\n" . $msg;
    
    if (mail($to, $subject, $body)) { header("Location: sent.html"); }
    else { header("Location: error.html"); }
    ?>

  • #4
    New Coder
    Join Date
    Dec 2004
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, worked great.

  • #5
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by Abel
    I've been working on a email script all day now with no such luck. I thought this would be very easy, but I guess not. None of the email scripts I found seem to work the way I want. I have the form page up fine. It's the action that I'm having trouble with. I don't want the action to be simply mailto:blah@blah.com. Does anyone have a good php script I could use?

    Thanks.
    abel this 1 will work, change the fields to get the message accordingly
    PHP Code:
    <?php 
    $to 
    "youremail@yourdomain.com";
    $Subject "yourubjectl";
    $message "NAME: {$_POST['fieldname']} {$_POST['surname']}, DOB:{$_POST['DOB']}, Year in school: 
    {$_POST['school_year']}, siblings: {$_POST['siblings']}, bedtime: {$_POST['bedtime']}, 
    homework time: {$_POST['homework']}, tv time: {$_POST['tv']}, computer time: {$_POST['computer']}, 
    family time: {$_POST['family']}, time with friends: {$_POST['friends']}"
    ;
    mail($to,$Subject,$message);
    if(
    mail){
    echo 
    "<BR />Thanks, message sent";
    }
    else{
    echo 
    "<BR /> An Error occured";

    ?>

  • #6
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    and this on the page with your form on
    <form action="pagewithemailscript.php" method="post">

  • #7
    New Coder
    Join Date
    Oct 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is a response to the post from Abel and reply by Rafiki

    I used your script pretty much as is except I changed the variable names to match my HTML form and it seemed to work fine except that I didn't receive any email. Any suggestions?
    Last edited by pkarovsky; 09-26-2006 at 06:06 PM.

  • #8
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did you place your email in the variable too?
    Is a spam filter blocking the email?
    Have you tried specifying a different email to see that works?
    Does the page navigate to sent.html (no error occured)?

  • #9
    New Coder
    Join Date
    Oct 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reply to Mark87

    Mark -- I sent you a private email by mistake, sorry. I'm using the php coding in your posting #3

    I get the following error message


    Warning: Cannot modify header information - headers already sent by (output started at /home/interven/public_html/mailform.php:9) in /home/interven/public_html/mailform.php on line 21

    No, I did not get to "sent.html"
    Last edited by pkarovsky; 09-27-2006 at 03:29 AM. Reason: Responding on forum rather than privately

  • #10
    New Coder
    Join Date
    Oct 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Rafiki post #6 (09-03-2006 05:18 AM)

    I tried your php code Rafiki and it worked without any errors but I didn't get any email?? I got the "message sent" page.

    Once again I used "myusername@yahoo.com" rather than at my domainname.com. Does this matter?
    Last edited by pkarovsky; 09-27-2006 at 03:25 AM. Reason: typo

  • #11
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Try it from another domain, such as a gmail account. If gmail thinks it's spam, at least it won't get thrown away before you ever see it.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #12
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    when i use my mail script i sent it to my gmail inbox and it was actually in my email inbox, not spam, didnt ever try hotmail or yahoo.. also try giving it a subject that doesnt look like a spam mail!
    Last edited by rafiki; 09-27-2006 at 12:48 PM.

  • #13
    New Coder
    Join Date
    Oct 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reply to Rafiki

    You were right. Yahoo was deleting the message as spam. I changed the subject and then it worked.

    I need to send the person to a page rather than just getting the "your message has been sent" however. Can you help with this.

    THANKS!

  • #14
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you're using Rafiki's code, use the if statement from mine instead...

    if (mail($to, $subject, $body)) { header("Location: sent.html"); }
    else { header("Location: error.html"); }

  • #15
    New Coder
    Join Date
    Oct 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mark87 et al

    Thanks to all of you for your help. Much appreciated


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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