Trouble sending e-mail through PHP

Discussion in 'Email' started by Jordan Carter, Jan 9, 2016.

  1. I have this very basic HTML:

    First Name: <input id="first" type="text" name="first"><br>
    Email: <input id="email" type="text" name="email"><br>
    <button id="formButton">OK</button>

    and jQuery

    $('#formButton').click(function(){

    var email = $('#email').val();
    var first = $('#first').val();
    var varData ='name=' + first + '&email=' + email;

    $.ajax({
    type: "POST",
    url: "mail_handler.php",
    data: varData,
    success: function (){
    alert("success");
    }
    });
    });

    and here's the PHP mail_handler file:

    <?php

    $name = $.POST['name'];
    $email = $.POST['email'];

    mail($email, $name, 'Thank you');
    ?>

    When I try to send an e-mail to myself using this, I get the success alert, but receive no e-mail.

    I searched the forum and saw that I might have to include this somewhere, but if so, where?:

    <?php
    require_once "Mail.php";
    $from = "Sender <[email protected]>";
    $to = "Recipient <[email protected]>";
    $subject = "This is a test email sent via php";
    $body = "This is a test email";
    $host = "mail.HostingAccountDomain.com";
    $username = "[email protected]";
    $password = "email_password";
    $headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject);
    $smtp = Mail::factory('smtp',
    array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));
    $mail = $smtp->send($to, $headers, $body);
    ?>

    Thanks for any and all help in resolving this issue.
     
  2. Update: I included this code in my home.php file, and I filled in the placeholder information with the required info. Now whenever I load my website, I get an e-mail about 10 minutes later from postmaster saying this is a test e-mail, but I do not get any e-mails from filling out my form and clicking the ok button.

    I have tried sticking in the require_once php code inside of my mail_handler.php file, so that way it gets executed at the same time as the php code related to my contact form, but now I am receiving no e-mail at all.
     

Share This Page