1

I have tried using my contact form with XAMPP i have configured .ini files etc. correctly to GMAIL for testing purposes. Can you see where I have made a mistake?

I have even tried WAMP and still nothing works.

I changed the xwamp files as this guy suggested: How to configure XAMPP to send mail from localhost?

HTML

<form method="post" action="contact-form.php" name="contactform" id="contactform">
    <fieldset>
        <input name="name" type="text" id="name" placeholder="Name"/> 
        <input name="email" type="text" id="email" placeholder="Email"/>  
        <input name="subject" type="text" id="subject" placeholder="Subject"/> 
    </fieldset>
    <fieldset> 
        <textarea name="comments" cols="40" rows="3" id="comments" placeholder="Message"></textarea>
    </fieldset>
    <input type="submit" class="submit" id="submit" value="Send Message" />
</form>

JS

 $('#contactform').submit(function(){
    var action = $(this).attr('action');
    $("#message").slideUp(250,function() {
        $('#message').hide();
        $('#submit')
            .after('<img src="img/assets/cbp-loading.gif" class="loader" />')
            .attr('disabled','disabled');
        $.post(action, {
            name: $('#name').val(),
            email: $('#email').val(),
            subject: $('#subject').val(),
            comments: $('#comments').val(),
        },
            function(data){
                document.getElementById('message').innerHTML = data;
                $('#message').slideDown(250);
                $('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
                $('#submit').removeAttr('disabled');
                if(data.match('success') != null) $('#contactform').slideUp(850, 'easeInOutExpo');
            }
        );
    });
    return false;   

PHP

 <?php
if (isset($_POST["submit"])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = 'Message from Contact Demo ';
    $message = $_POST['message'];
    $from = 'Demo Contact Form'; 
    $to = 'myemail@gmail.com'; 
    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
    mail('myemail@gmail.com', $name, $email, $subject, $message);
}
?>

Sendmail code (i have removed the email and password obviously)

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=MYEMAIL@gmail.com
auth_password=MY EMAIL PASSWORD
force_sender=MYEMAIL@gmail.com
Community
  • 1
  • 1
  • 2
    Where's your `mail()` function? – aynber Dec 20 '16 at 13:39
  • something I must have missed, I'm new to php, where should I add this, :z – digitalhive Dec 20 '16 at 13:40
  • That's the function that does the actual send, so it needs to go after you set your body, subject, etc. More information can be found [https://secure.php.net/manual/en/function.mail.php](in the documentation). – aynber Dec 20 '16 at 13:41

2 Answers2

0

One of the most underestimated points is to no start XAMPP as administrator. In addition I'm missing some configuartions for smtp and co:

$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'EMAIL',
        'password' => 'PASSWORD'
    ));

Those are necessary to be allowed to sent to your email adress. If not anyone could spam your email adress.

Sincerely liqSTAR

liqSTAR
  • 1,225
  • 1
  • 12
  • 22
0

There's no mail() function in the PHP code.

Would recommend stripping back to the simplest test case to start with. As a first test I would recommend writing a simple PHP file that just utilises the mail() function to send an email to your own address and returns the result (be sure to also check the PHP error log) - this will help to confirm PHP is configured with a working SMTP server.

I'd then try the form submission without the use of JavaScript to ensure that it's submitting okay. Does the $.post action appear in the console okay? Does it show anything as the response or status code?

jedi58
  • 319
  • 3
  • 9