Skip to main content
webmaster698
Known Participant
December 29, 2016
Answered

Dreamweaver Auto Responder when a user Submits a form

  • December 29, 2016
  • 17 replies
  • 3652 views

Hi,

I am trying to add an auto responder to one of my existing forms I made in Dreamweaver.  If it has to be php, please give me detailed instructions on how to set up the form, and more importantly, how to set up a php file.  Also, where does that php file go? Where on the server?

Thanks so much!

Greg

    This topic has been closed for replies.
    Correct answer osgood_

    You nearly had it - you need to construct the $email_body variable (see below)

    <?php

    if ($_POST){

    $name = substr(strip_tags(html_entity_decode($_POST['name'])),0,50);

    $company = substr(strip_tags(html_entity_decode($_POST['company'])),0,50);

    $phone = substr(strip_tags(html_entity_decode($_POST['phone'])),0,15);

    $subject = substr(strip_tags(html_entity_decode($_POST['subject'])),0,50);

    $message = substr(strip_tags(html_entity_decode($_POST['message'])),0,200);

    $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);

    if ($name && $email && $company && $phone && $message ){

    $email_from = 'youremail@domain.com';//<== update the email address

    $email_subject = "New Form submission";

    $email_body = "You have received a new message from the user $name.\n";

    $email_body .= "Here is the message:\n";

    $email_body .= "Name: $name\n";

    $email_body .= "Company: $company\n";

    $email_body .= "Phone Number: $phone\n";

    $email_body .= "Subject: $subject\n";

    $email_body .= "Message: $message\n";

    $to = "webmaster@voipccg.com";//<== update the email address

    $headers = "From: $email_from \r\n";

    $headers .= "Reply-To: $email \r\n";

    mail($to,$email_subject,$email_body,$headers);

    mail($email,$email_subject,"Your email has been received.",$headers);

    $message="The message has been emailed."; 

    }

    }

    ?>

    <!doctype html>

    <html>

    <head>

    <meta charset="utf-8">

    <title>Form Example</title>

    </head>

    <body>

    <?php echo $message; ?>

    <form action='' method='post'>

    <p>Email: <input name='email' type='email'  required/></p>

    <p>Name: <input name='name' type='text'  required/></p>

    <p>Company: <input name='company' type= 'text' required/></p>

    <p>Phone: <input name='phone' type= 'text' required/></p>

    <p>Subject: <input name='subject' type= 'text' required/></p>

    <p>Message: <input name='message' type= 'text' required/></p>

    <p><input name='submit' type='submit'/></p>

    </form>

    </body>

    </html>

    17 replies

    webmaster698
    Known Participant
    December 31, 2016

    Hey,

    I've been tinkering around trying to forward the form to another page, when the user hits submit.  I tried putting in a forwarding page in the <form action='' method='post'> attribute.  Does it have to be a .php page, or could it be a .html page?  I tried it both ways, but either way, it does not send the email.  It does forward to the other page.

    Or maybe, the form could be set so the form fields disappear when the user hits submit, and all they see is the message saying the form has been emailed.  I don't know if that is accomplished by the use of a forwarding page. 

    Has anyone had any success?

    Thanks

    Legend
    December 31, 2016

    webmaster698 wrote:

    Or maybe, the form could be set so the form fields disappear when the user hits submit, and all they see is the message saying the form has been emailed. I don't know if that is accomplished by the use of a forwarding page.

    <?php if(isset($message)) {

    echo $message;

    }

    else { ?>

    <form action='' method='post'>

    <p>Email: <input name='email' type='email'  required/></p>

    <p>Name: <input name='name' type='text'  required/></p>

    <p>Company: <input name='company' type= 'text' required/></p>

    <p>Phone: <input name='phone' type= 'text' required/></p>

    <p>Subject: <input name='subject' type= 'text' required/></p>

    <p>Message: <textarea name='message' required/></textarea></p>

    <p><input name='submit' type='submit'/></p>

    </form>

    <?php } ?>

    webmaster698
    Known Participant
    December 30, 2016

    I'm sorry, but I don't understand something. For the message field, I changed it from a textbox to a text area. Now the form won't work, but I don't see where else in the code it needs to be changed. Can you help?

     

    webmaster698
    Known Participant
    December 30, 2016

    Nevermind, I got it to work.

    webmaster698
    Known Participant
    December 30, 2016

    Hey,

    I'm sorry, but I don't understand something. For the message field, I changed it from a textbox to a text area. Now te form won't work, but I don't see where else in the code it needs to be changed. Can you help?

    Legend
    December 30, 2016

    You should only need to change the <input> form field to a <textarea></textarea> field:

    <p>Message: <textarea name='message' required/></textarea></p>

    webmaster698
    Known Participant
    December 30, 2016

    Thanks for the reply.  I got it to work.  I was just doing something stupid. Thanks though

    webmaster698
    Known Participant
    December 30, 2016

    ok, I followed your instructions for the name tag, and it works.  So I did all the same stuff for my other form fields, but they don't work.  This is what I have:

    <?php

    if ($_POST){

    $name = substr(strip_tags(html_entity_decode($_POST['name'])),0,50);

    $company =     substr(strip_tags(html_entity_decode($_POST['company'])),0,50);

    $phone = substr(strip_tags(html_entity_decode($_POST['phone'])),0,50);

    $subject = substr(strip_tags(html_entity_decode($_POST['subject'])),0,50);

    $message = substr(strip_tags(html_entity_decode($_POST['message'])),0,50);

    $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);

    if ($name && $email){

    $email_from = $email;//<== update the email address

    $email_subject = "New Form submission";

    $email_body = "You have received a new message from the user $name.\n".

    $name = substr(strip_tags(html_entity_decode($_POST['name'])),0,50);

    $company =     substr(strip_tags(html_entity_decode($_POST['company'])),0,50);

    $phone = substr(strip_tags(html_entity_decode($_POST['phone'])),0,50);

    $subject = substr(strip_tags(html_entity_decode($_POST['subject'])),0,50);

    $message = substr(strip_tags(html_entity_decode($_POST['message'])),0,50);

        "Here is the message:\n $message";

    $to = "webmaster@voipccg.com";//<== update the email address

    $headers = "From: $email_from \r\n";

    $headers .= "Reply-To: $email \r\n";

    if (mail($to,$email_subject,$email_body,$headers)){

        mail($email,$email_subject,"Your email has been received.",$headers);

    $message="The message has been emailed.";  

    } else {

    $message = "good email and name, but could not send.";  

    }} else {

    $message = "Bad email, or bad name, or bad day!";  

    }

    }

    ?>

    <!doctype html>

    <html>

    <head>

    <meta charset="utf-8">

    <title>Form Example</title>

    </head>

    <body>

    <?php echo $message; ?>

    <form action='' method='post'>

    <p>Email: <input name='email' type='email'  required/></p>

    <p>Name: <input name='name' type='text'  required/></p>

    <p>Company: <input name='company' type= 'text' required/></p>

    <p>Phone: <input name='phone' type= 'text' required/></p>

    <p>Subject: <input name='subject' type= 'text' required/></p>

    <p>Message: <input name='message' type= 'text' required/></p>

    <p><input name='submit' type='submit'/></p>

    </form>

    </body>

    </html>

    Rob Hecker2
    Legend
    December 30, 2016

    This is my final post on this thread. As I said before, you need to learn a little bit about HTML and PHP. Your code example above demonstrates that you don't understand what a "variable" is. That is a term you would learn in the first fifteen minutes of any lesson on PHP.

    There are many introductory tutorials on the web on PHP and HTML. Lynda.com has a good collection of tutorials.

    We have spent two days going back and forth because you have not yet spent a single hour learning PHP.

    Stop what you are doing and go learn a little bit about this stuff. Then come back here when you get stuck.

    webmaster698
    Known Participant
    December 30, 2016

    All I was missing was the

    $email_body variable

    webmaster698
    Known Participant
    December 30, 2016

    ok, I'm getting it.

    webmaster698
    Known Participant
    December 30, 2016

    I'm sorry, where do I add that name tag?

    And what about the others?

    webmaster698
    Known Participant
    December 29, 2016

    I was also wondering if I can put a capcha on my form. Some way to keep the go s way. Do you know of anything?

    BenPleysier
    Community Expert
    Community Expert
    December 29, 2016
    Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
    Rob Hecker2
    Legend
    December 29, 2016

    I personally really really hate recapchas. Very often it takes me more than one try to get it right, which is a buzz kill.

    I have found that using a honeypot works well, and doesn't punish the form submitter.

    Don't put style=display:none in the input tag of your honey pot. Put it in a class the honeypot uses. Make the honeypot seem like a normal question.

    If a honey pot doesn't turn out to be enough, then validating user input can be an additional way to filter out spam. For instance, often the spam tries to put email addresses in any field, so you can reject form submissions that have email addresses as responses to questions like: do you like ice cream?

    webmaster698
    Known Participant
    December 29, 2016

    Thanks! It works great.  Tomorrow, I'll continue adding form fields to this.  If I run into trouble, I'll post to this forum again.

    webmaster698
    Known Participant
    December 29, 2016

    One more thing:

    This is the message I receive on the tech or agent side:

    You have received a new message from the user Gregory.

    Here is the message:

    webmaster@voipccg.com

    How do I get rid of it saying "webmaster@voipccg.com".

    Rob Hecker2
    Legend
    December 29, 2016

    Replace the period with a semicolon, like this:

    "Here is the message:\n $message";

    Rob Hecker2
    Legend
    December 29, 2016

    I'll mention that I NEVER use the PHP mail function. It's a good way to get your emails delivered to the spam folder.

    I use the swiftmailer class. David Powers has a good tutorial about it on lynda.com.

    webmaster698
    Known Participant
    December 29, 2016

    so what do I edit this line with to grab the user's email, and not just mine:

    $email_from = 'webmaster@voipccg.com';//<== update the email address

    Rob Hecker2
    Legend
    December 29, 2016

    $email_from = $email;//<== update the email address