0

I have a contact form for my website and am hoping to modify it so that a confirmation email is sent to the user when they click submit. Can anybody advise me on the best way to do this?

My php is pretty simple:

 // validation complete 

if(isset($_POST['submit'])){

if($msg_name=="" && $msg2_name=="" && $msg_email=="" && $msg2_email=="" && 
$msg2_Message=="")

$msg_success = "Thankyou for your enquiry";

//send mail   

    $EmailFrom = "someone@somewhere.co.uk";

    $EmailTo = "someone@somewhere.co.uk";

    $Subject = "Online contact form";

    $full_name = Trim(stripslashes($_POST['full_name'])); 

    $Phone_Num = Trim(stripslashes($_POST['Phone_Num'])); 

    $email_addr = Trim(stripslashes($_POST['email_addr'])); 

} 

    // prepare email body text

    $Body = "";

    $Body .= "full_name: ";

    $Body .= $full_name;

    $Body .= "\n";

    $Body .= "Phone_Num: ";

    $Body .= $Phone_Num;

    $Body .= "\n";

    $Body .= "email_addr: ";

    $Body .= $email_addr;

    $Body .= "\n";


    // send email 

    $success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");

    ?>
Amber Sabre
  • 143
  • 9
  • 2
    `if (all entries are empty) { thanks for your inquiry }` makes no sense... – Marc B Nov 28 '13 at 20:18
  • It's unclear as to what your question is. Is your code working? You should use mail() to notify the user. Just to note: I don't think you're supposed to capitalize the t of trim. – sheng Nov 28 '13 at 20:19
  • What does the if($msg_name=="" ... achieve. Remove that and try sending. – crafter Nov 28 '13 at 21:14

2 Answers2

0

First we get the mailto function to work with localhost and email client:
Check this link on stackoverflow:
URL link: send email to owner by collecting information provided by user through form?

Then I recommend using Swiftmailer. http://swiftmailer.org/docs/sending.html They got the best manual.

Community
  • 1
  • 1
KarlosFontana
  • 188
  • 2
  • 7
0

As others have already suggested the "if" statement is useless since it is achieving nothing. I think your idea was to verify if the fields that you have in your contact form are filled or not. If the fields are unavailable you should throw some error which you are not doing.

Also, if you are to send a confirmation mail to the user who clicks the submit button then the $EmailTo variable should take the email from $msg_email or $msg2_email which according to the code is not done here.

Check this simple snippet this might help you:

if ($_POST['submit']) {
  if ($_POST['name1] == '')
    echo "Please provide the first name";
  if ($_POST['name2] == '')
    echo "Please provide the last name";
  if ($_POST['email1] == '')
    echo "Please provide the email";        
  if ($_POST['email2] == '')
    echo "Please provide the alternate email";
  if ($_POST['message] == '')
    echo "Please provide the Message";

//Send email to your inquiry mail with above details

// Confirmation mail

    $message =<<<EOM
    Dear $_POST['name1'],
    Thank you for your inquiry. 
    Our executives will get back to you ASAP.

    Thanks, 
        Sales
    EOM;    

    $to = $_POST['email1'];
    $subject = "Acknowledgement of Inquiry";
    $headers = "Content-Type: text-plain";
    $headers .= "From: sales@yourcompany.co.uk";

    mail($to, $subject, $message, $headers);

}
Pirus
  • 1