The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 11 of 11

Thread: php plus html auto responder

  1. #1

    php plus html auto responder

    Is there a way after someone enters their email address in my flash contact form I can send them an HTML email automatically? I have the letter i want to send already made and it works fine if i send it from my emali account. But i'd like to miss out the middle part if possible and just "auto respond in html" i guess.

    Many thanks

    Greg

  2. #2
    Assuming you have some sort of php script working in the background that sends you the message from the user, just add another function that sends an email to their specified address.

  3. #3
    Hi Duncan

    Yes i am using a php script that looks like this (from an earlier Kirupa tutorial)

    HTML Code:
    <?php
    
    $sendTo = "g_rochford@xxx.co.uk";
    $subject = "Contact Form";
     
    $headers = "From: " . $_POST["email"] . "\r\n";
    
    $headers .= "Reply-To: " . $_POST["email"] . "\r\n";
    
    $headers .= "Return-path: " . $_POST["email"];
     
    $message .= "Message: " . $_POST["msg"] . "\r\n";
    $message .= "Name: " . $_POST["name"] . "\r\n";
    $message .= "Email: " . $_POST["email"] . "\r\n";
    
    mail($sendTo, $subject, $message, $headers);
     
    if($email=="undefined" || $subject=="undefined" || $message=="undefined"){
    echo "Please fill in all the fields";
    }else{
    echo "Thankyou for registering.";
    
    mysql_connect("localhost", "xxx", "Franzxxx");
    mysql_select_db("www_philcampbellmusic_com");
    mysql_query("INSERT INTO `Phil` (`email`,`subject`,`message`) VALUES ('$headers','$subject','$message')");
    }
     
    ?>
    but im a total newbie to php. Could you suggest something please.

    Many thanks again.

    Greg
    Last edited by g_rochford; January 12th, 2007 at 07:42 AM.

  4. #4
    you should also check out your host provider as they usually provide a means via the interface to auto respond to emails that are sent to any given address.

  5. #5
    Er, dude, you've just shown all your database details to anyone who wants it - password, login etc.

    I'll post the php script you need in a bit, but I'd edit your post asap if I were you, in case there's some unsavoury characters about.

  6. #6
    Ok, so this is pretty basic but hopefully you'll get the idea. All I've done really is replicated your email function so that it gets called once the user has successfully signed up:

    PHP Code:
    <?php
    $sendTo 
    "g_rochford@xxx.co.uk";
    $subject "Contact Form";
    $headers "From: " $_POST["email"] . "\r\n";
    $headers .= "Reply-To: " $_POST["email"] . "\r\n";
    $headers .= "Return-path: " $_POST["email"];
    $message .= "Message: " $_POST["msg"] . "\r\n";
    $message .= "Name: " $_POST["name"] . "\r\n";
    $message .= "Email: " $_POST["email"] . "\r\n";

    mail($sendTo$subject$message$headers);

    function 
    autoRespond($user_email) {
        
    $ar_recipient "$user_email";
        
    $ar_subject "Thank You For Registering at PhilCampbellMusic.com";
        
    $ar_headers "From: "someone@philcampbellmusic.com"\r\n";
        
    $ar_headers .= "Reply-To: "someone@philcampbellmusic.com"\r\n";
        
    $ar_message "Message: " YOUR AUTO RESPONSE MESSAGE HERE";

        mail(
    $ar_recipient , $ar_subject , $ar_message$ar_headers);
    }
     
    if(
    $email=="undefined" || $subject=="undefined" || $message=="undefined"){
        echo "
    Please fill in all the fields";
    }else{
        echo "
    Thankyou for registering.";

        mysql_connect("
    xxx", "xxx", "xxx");
        mysql_select_db("
    www_philcampbellmusic_com");
        mysql_query("
    INSERT INTO `Phil` (`email`,`subject`,`message`) VALUES ('$headers','$subject','$message')");
        autoRespond(
    $_POST["email"]);
    }
    ?>

  7. #7
    Hi Duncan,

    Thanks for your help, thats brilliant.

    Also thanks for your concern i"ll change the details to my server now.

    Instead of a message, do you know how i can send a complex html document instead of just text?

    Greg

  8. #8
    It shouldn't be too difficult but I haven't done any PHP email stuff for a fair while so the technique eludes me.

    Have a look at http://www.phpfreaks.com/tutorials/130/0.php - that seems to have some fairly comprehensive information.

  9. #9
    Hi Duncan

    I tried putting your code in, but it stoped the php form from working at all, and make the bottom half of the code in dreamweaver look wrong???

    I dont really understand the syntax but i changed the end of the last line which made it look right again in dreamweaver. I added . "\r\n"

    HTML Code:
    function autoRespond($user_email) {
        $ar_recipient = "$user_email";
        $ar_subject = "Thank You For Registering at PhilCampbellMusic.com";
        $ar_headers .= "From: "someone@philcampbellmusic.com . "\r\n";
        $ar_headers .= "Reply-To: "someone@philcampbellmusic.com . "\r\n";
        $ar_message .= "Message: " YOUR AUTO RESPONSE MESSAGE HERE . "\r\n";
    
        mail($ar_recipient , $ar_subject , $ar_message, $ar_headers);
    }
    Sorry to be a pain, but im still confused and lost

    Greg

  10. #10
    Whoops, a bit of concatenation mixup.

    Try this:

    PHP Code:
     <?php
    $sendTo 
    "g_rochford@xxx.co.uk";
    $subject "Contact Form";
    $headers "From: " $_POST["email"] . "\r\n";
    $headers .= "Reply-To: " $_POST["email"] . "\r\n";
    $headers .= "Return-path: " $_POST["email"];
    $message .= "Message: " $_POST["msg"] . "\r\n";
    $message .= "Name: " $_POST["name"] . "\r\n";
    $message .= "Email: " $_POST["email"] . "\r\n";

    mail($sendTo$subject$message$headers);

    function 
    autoRespond($user_email) {
        
    $ar_recipient "$user_email";
        
    $ar_subject "Thank You For Registering at PhilCampbellMusic.com";
        
    $ar_headers "From: someone@philcampbellmusic.com \r\n";
        
    $ar_headers .= "Reply-To: someone@philcampbellmusic.com \r\n";
        
    $ar_message "Message: YOUR AUTO RESPONSE MESSAGE HERE";

        
    mail($ar_recipient $ar_subject $ar_message$ar_headers);
    }
     
    if(
    $email=="undefined" || $subject=="undefined" || $message=="undefined"){
        echo 
    "Please fill in all the fields";
    }else{
        echo 
    "Thankyou for registering.";

        
    mysql_connect("xxx""xxx""xxx");
        
    mysql_select_db("www_philcampbellmusic_com");
        
    mysql_query("INSERT INTO `Phil` (`email`,`subject`,`message`) VALUES ('$headers','$subject','$message')");
        
    autoRespond($_POST["email"]);
    }
    ?>

  11. #11
    Thanks Ducan

    It works an absolute dream now. Perfect! Many Many thanks! Now if i could just send a complex html I'd be there!

    Greg

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012