Making an autoresponder in php

Scorpion Ghost

Elite Member
Executive VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
9,144
Reaction score
10,489
I have a website that has a contact form. And when someone uses it I receive the message. But I would like to set up an autoresponder to inform the person who contacted me that their message has been received etc.

<?php
$data = json_decode(file_get_contents('admin/data/contact.txt'));
include('includes/header.php');
if(isset($_REQUEST['name'])) {
$to = $settings->email;
$subject = 'Contact from Website';
$headers = "From: " . strip_tags($_REQUEST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_REQUEST['email']) . "\r\n";
//$headers .= "CC: [email protected]\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "Hi, A message from contact form.";
$message .= "<br /><br /><br />Name: ".$_REQUEST['name'];
$message .= "<br />Email: ".$_REQUEST['email'];
$message .= "<br />Subject: ".$_REQUEST['subject'];
$message .= "<br />Message: ".$_REQUEST['message'];
mail($to, $subject, $message, $headers);
$msg = 'Your Message has been sent. Thank You.';
}
$btn = '<input type="submit" style="font-size: 14px; font-style: normal; height: auto; color: #fff; border-radius: 15px; border: none;" class="btn_new" value="SEND" />';
?>

I'm pretty sure a few lines of code added here would do the trick, but I don't know how to do it. I tried a few things, but it didn't work. How can I edit this code in order to set this up?

Thank you
 
Hey

FIrst off I would suggest using an SMTP to send the email, it would increase the chances of delivery. Secondly, I would suggest using a library like PHPMailer, makes everything easier and better (can be used with SMTP easily aswell).

You are saying you want to make an autoresponder but that code is actually the part to send the notification to you that something filled the contact form.
What you can do, if you do not want to use a library and make everything simple (without changing much, or anything), simply add the code below:

Code:
mail($_REQUEST['email'], "Your message has been received!", "Hey we would like to let you know that we received your message. You should hear from us in less than 24 hour., $headers);

(Maybe you could change the $headers a bit too).

Also, I am not sure how you are handling the requests, but in a form it's usually $_POST (still depends on configuration/setup/framework).
 
Hey

FIrst off I would suggest using an SMTP to send the email, it would increase the chances of delivery. Secondly, I would suggest using a library like PHPMailer, makes everything easier and better (can be used with SMTP easily aswell).

You are saying you want to make an autoresponder but that code is actually the part to send the notification to you that something filled the contact form.
What you can do, if you do not want to use a library and make everything simple (without changing much, or anything), simply add the code below:

Code:
mail($_REQUEST['email'], "Your message has been received!", "Hey we would like to let you know that we received your message. You should hear from us in less than 24 hour., $headers);

(Maybe you could change the $headers a bit too).

Also, I am not sure how you are handling the requests, but in a form it's usually $_POST (still depends on configuration/setup/framework).

Hey man, thanks. I figured it out eventually. Did something similar to what you wrote there with the code.

I see you know what you're talking about, but I don't :p so I couldn't go implementing SMTP and PHPMailer and libraries and all that. I don't understand any of that haha.

How I solved it is I asked the same question on Stackoverflow, and someone answered but didn't give a correct answer, but gave me something to work with, and after tinkering with it I managed to figure it out and make it functional. I tested it, it all works, I'm good.

Thanks :)
 
Back
Top