Hello,

I have been trying to make contact us works. It appears that it works like I receive a success message but in actual it doesn't work like it suppose to:

index.php

<form action="contact.php" name="contactform" class="row" method="post">

                                    <h4>Request a FREE TRIAL CLASS!</h4>

                                    <div id="input_name" class="col-md-12">
                                        <input id="name" class="form-control" type="text" name="stu_fname" placeholder="Full Name"> 
                                    </div>

                                    <div id="input_email" class="col-md-12">
                                        <input id="email" class="form-control" type="text" name="stu_email" placeholder="Enter your email"> 
                                    </div>

                                    <div id="input_phone" class="col-md-12">
                                        <input id="phone" class="form-control" type="text" name="stu_telp" placeholder="Phone Number"> 
                                    </div>   

                                    <p>We will respond to you within 24 hours, during regular business hours. All fields are required</p>

                                    <!-- Submit Button -->
                                    <div id="form_register_btn" class="text-center">

                                    <input class="btn btn-theme" type="submit" name="request" value="Request Quotation" id="submit">

                                    </div>  

contact.php

<body>

<?php

include('includes/koneksi.php');


// PHP Mailer 

require 'C:/xampp/htdocs/phpmailer/PHPMailerAutoload.php';
 //memanggil library php mailernya


function smtpmailer($to, $from, $from_name, $subject, $body) {

global $error;

$mail = new PHPMailer();

//$mail->AuthType = 'NTLM';

$mail->IsSMTP();

//$mail->SMTPDebug = 0;  // untuk memunculkan pesan error /debug di layar

$mail->SMTPAuth = true;  // authentifikasi smtp enable atau disable

$mail->SMTPSecure = "";//‘ssl atau di kosongkas jika none’; // secure transfer membutuhkan authentifikasi dari mail server

$mail->Host ='ssl://smtp.gmail.com:465;tls://smtp.gmail.com:587'; // masukkan nama host email “diawal ssl://”

$mail->Port = 587; //port secure ssl email

$mail->Username = "squprime@gmail.com"; //username email

$mail->Password = "********"; //password email

$mail->SetFrom($from, $from_name);

$mail->Subject = $subject;

$mail->Body = $body;

$mail->AddAddress($to);

if(!$mail->Send()) {

$error = "Mail error: ".$mail->ErrorInfo;

return false;

} else {

$error = "Message sent!";

return true;

}

}


    $result = mysql_query("SELECT * FROM student ORDER BY student_id DESC") or die(mysql_error());
    //$result = mysql_query("SELECT student_id FROM student ORDER BY student_id DESC") or die(mysql_error());
    $data = mysql_fetch_array($result);


// write program to send email to the recorded email address


    $name = $data['stu_fname'];
    $email = $data['stu_email'];
    $phone = $data['stu_telp'];
    $message = "Dear ".$data['stu_fname'].","."\r\r".
    "Please click the link below to continue the registration progress: ".
    "http://www.squprime.com/registration3.php?student_id=".$data['student_id'];

    /*if (@$_POST['submit']) {*/
    if ($name&&$email&&$phone&&$message) {
    if (is_numeric($phone)) {

    $body = "
    Name: ".$name."
    Phone: ".$phone."
    Email: ".$email."\n\n
    ".$message;

    smtpmailer("squprime@gmail.com", "squprime@gmail.com", "Davy", "Test Email", $body); 
    //smtpmailer("squprime@indonusa.net.id", "squprime@indonusa.net.id", "Davy", "Test Email", $body); // script kirim email

    echo "Your message has been sent, we will get back to your shortly.";
    $name = trim("");
    $email = trim("");
    $phone = trim("");
    $message = trim("");
    }
    else
    echo "There should only be numbers in your phone number.";
    } 
    else
    echo "Please fill in <b>all</b> the fields!";


?>  





        <div id="contentForm">

            <?php
            header('Content-Type: text/html; charset=utf-8');

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


                // EDIT THE 2 LINES BELOW AS REQUIRED

                //$email_to = "cs@squprime.com";
                $email_to = "squprime@gmail.com";

                $email_subject = "SquPrime Free trial request!";


                $first_name = $_POST['first_name']; // required 
                $email_from = $_POST['email']; // required
                $phone = $_POST['phone']; // required

                $email_message = "Form details below.\n\n";


                function clean_string($string) {
                    $bad = array("content-type","bcc:","to:","cc:","href");
                    return str_replace($bad,"",$string);
                }


                $email_message .= "Name: ".clean_string($first_name)."\n";
                $email_message .= "Email Address: ".clean_string($email_from)."\n";
                $email_message .= "Phone Number: ".clean_string($phone)."\n";


                // create email headers

                $headers = 'From: '.$email_from."\r\n".

                'Reply-To: '.$email_from."\r\n" .

                'X-Mailer: PHP/' . phpversion();

                //@mail($email_to, $email_subject, $email_message, $headers);

                mail($email_to, $email_subject, $email_message, $headers);  

                ?>

                <!-- Message sent! (change the text below as you wish)-->
                <div class="container">
                    <div class="row">
                        <div class="col-sm-6 col-sm-offset-3">
                            <div id="form_response" class="text-center">
                                <img class="img-responsive" src="img/thumbs/mail_sent.png" alt="image" />
                                <h1>Your request is sent!</h1>
                                <p>Thank you <b><?=$first_name;?></b>, our advisor will contact you within 24 hours!</p>
                                <a class="btn btn-theme btn-lg" href="index.php">Back To The Site</a>
                            </div>
                        </div>   
                    </div>                   
                </div>
                 <!--End Message Sent-->

                <?php

                }

                ?>

        </div>

    </body>

The message that is appears:

Your message has been sent, we will get back to your shortly.

When I check my email address I do not receive anything. I also check my student table database, no new row registration being added.

The message that is appears

That message will be shown every time, whether or not mail() returns true or false.

<?php
$to="mail@mail.com";
$subject="Query From your client";
$frommail=$_POST['email'];


mail($to,$subject,$msg,$headers) ;
//header("Location:Contact-us.php?msg=msg");

?>
<script type="text/javascript" language="javascript">
location.href="contactus.php?msg=msg";
</script>

This is the only code that you want.

I already put the condition:

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

So it suppose to work if the condition is true, correct?

I meant that mail() returns true if the mail is successfully queued. Check that value first.

How to check the value?

I try this:

contact.php

$ok = @mail($email_to, $email_subject, $email_message, $headers);   
if($ok){ return true; } else { return false; }

The only message that appears:

Your message has been sent, we will get back to your shortly.

Instead of return true; you have to show your OK message. Replace return false; with a failed message.

ok, this is funny. I get a successful message but I cannot find the email anywhere in my mailbox.

Your message has been sent, we will get back to your shortly.
successfully sent message

-------------------------------------

I also do not see my table - database being added as it suppose to:

index.php

<!-- CONTENT WRAPPER
        ============================================= -->

        <div id="content_wrapper">

            <?php

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

            if(!empty($stu_fname) && !empty($stu_email) && !empty($stu_telp)){

            $sqlstr = "INSERT INTO student(stu_fname, stu_email, stu_telp) VALUES('".$stu_fname."','".$stu_email."','".$stu_telp."')";

            $result = mysql_query($sqlstr) or die(mysql_error());

            $result2 = mysql_query("SELECT student_id FROM student ORDER BY student_id DESC");

            $dataSID = mysql_fetch_array($result2);

            //header("location:registration2.php?student_id='".$dataSID['student_id']."'");
            } 
            else
            {           
            $error = "<i>Please fill-in all fields information in this form.</i><br>";

            $result = "";
            }

            //Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
            //if (empty($_REQUEST['id']))   kirimEmail($idKategori, $judul, $news);
            $confirmation = ($result) ? "Data has been saved." : "Fail to save data.";  

        }   ?>

            <!-- INTRO
            ============================================= -->
            <section id="intro">
                <div class="container">
                    <div class="row">


                        <!-- Intro Description -->
                        <div id="intro_description" class="col-md-7">
                            <center><img src="images/logo2.png" height="100px" style="margin-top: -120px;"></center><br>
                            <h1>Online Chinese Course</h1>
                            <h2> for business and corporate</h2>

                            <p>SQUPrime provides effective and easy solution to learn Mandarin in the convenience environment for Business person</p>

                            <p>We connect you to the best native teachers from trusted learning learning institutions in China through Live Video Call in affordable price.</p>

                            <!-- Store Buttons -->
                            <div id="intro_stores" style="margin-top: -80px;">
                                <a href="www.microsoft.com" target="_blank"><img src="img/icons/microsoft.png" alt="microsoft_icon" /></a>         
                                <a href="http://products.office.com/lync/" target="_blank"><img src="img/icons/lync.png" alt="lync_icon" /></a>
                                <a href="http://www.yamaha.com/products/en/communication/howto/webmeet/" target="_blank"><img src="img/icons/yamaha.png" height="60px" style="margin: 180px 0 0 -320px;" alt="yamaha_icon" /></a>
                                <!-- <a href="#"><img src="img/icons/windows.png" alt="windows_icon" /></a> -->
                            </div>

                        </div>   <!-- End Intro Description -->


                        <!-- Intro Form Register --> 
                        <div id="intro_form" class="col-md-5 form_register text-center">


                                <!-- Register Form -->   
                                <form action="contact.php" name="contactform" class="row" method="post">

                                    <h4>Request a FREE TRIAL CLASS!</h4>

                                    <div id="input_name" class="col-md-12">
                                        <input id="name" class="form-control" type="text" name="stu_fname" placeholder="Full Name"> 
                                    </div>

                                    <div id="input_email" class="col-md-12">
                                        <input id="email" class="form-control" type="text" name="stu_email" placeholder="Enter your email"> 
                                    </div>

                                    <div id="input_phone" class="col-md-12">
                                        <input id="phone" class="form-control" type="text" name="stu_telp" placeholder="Phone Number"> 
                                    </div>   

                                    <p>We will respond to you within 24 hours, during regular business hours. All fields are required</p>

                                    <!-- Submit Button -->

Have you tried to send an email with hard-coded values?

What's an email with hard-coded value?

When you send an email using your code, but instead of PHP dynamically putting content into the email, you manually type it in yourself. It's to check to make sure the PHP function is actually capable of sending an email.

okay, I'll try this:

smtpmailer("squprime@gmail.com", "squprime@gmail.com", "Davy", "Test Email", $body); 

I still have not receive anything yet.

There is a success message but no email address.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.