0

I am creating a 'Get a price enquiry' form using HTML and PHP. However, my website isn't live so I am working on XAMPP server - localhost.

I have been searching through many tutorials, changed both php.ini and sendmail.ini files, changed compatibility to Windows XP (service Pack 3) yet still haven't found a solution.

The email states no error when submit button is pressed but no email is coming through to my gmail account.

PriceRequest.php - Post form

if (isset($_POST['submit']))
{
    $firstName = $_POST ['firstName'];
    $lastName = $_POST ['lastName'];
    $email = $_POST ['email'];
    $telephoneNo = $_POST ['telephoneNo'];
    $customerTitle = $_POST ['customerTitle'];
    $enquiry = $_POST ['enquiry'];

    $formContent="From:$firstName $lastName \n Telephone No: $telephoneNo \n Enquiry: $enquiry 
                    \n Customer Title: $customerTitle";
    $recipient = "myemail@gmail.com";
    $subject = "Hardware Enquiry";
    $mailheader = "From: $email";

    //validate form         
    if (!filter_var($email, FILTER_VALIDATE_EMAIL))
        {
            $error = "Please enter valid email address";
        }
        else if(empty($firstName))
        {
            echo "First name must be entered";

        }
        else if(empty($telephoneNo))
        {
            echo "Telephone number must be entered";

        }
        else if(empty($customerTitle))
        {
            echo "Please choose your customer title";

        }
        else if(empty($enquiry))
        {
            echo "Please enter your enquiry";

        }

    if (mail($recipient, $subject, $formContent, $mailheader))
    {
        echo "<script>alert('Thank you for contacting us. We will be in touch with your soon')</script>"; 
        echo mail($recipient, $subject, $formContent, $mailheader);
    }
    else
        {

            die('Failure');
        }
}

PriceRequest.php - form

<form method="POST">
    <div class="requestPrice">
        <table width="700px" align="center">
        <h1 align="center">Request a Price</h1>

        <tr>
            <td valign="top">
                <label for="firstName">First Name *</label>
            </td>
            <td valign="top">
                <input type="text" name="firstName" maxlength="50" size="30" required />
            </td>
        </tr>

        <tr>
            <td valign="top">
                <label for="lastName">Last Name *</label>
            </td>
            <td valign="top">
                <input type="text" name="lastName" maxlength="50" size="30" required />
            </td>
        </tr>   

        <tr>
            <td valign="top">
                <label for="email">Email Address *</label>
            </td>
            <td valign="top">
                <input type="text" name="email" maxlength="80" size="30" required />
            </td>
        </tr>

        <tr>
            <td valign="top">
                <label for="telephoneNo">Telephone No. *</label>
            </td>
            <td valign="top">
                <input type="text" name="telephoneNo" maxlength="30" size="30" required />
            </td>
        </tr>

        <tr>
            <td valign="top">
                <label for="customerTitle">Customer Type *</label>
            </td> 
            <td>
            <select name="customerTitle">
                <option value="trade">Trade</option>
                <option value="homeowner">Homeowner</option>
                <option value="selfbuild">Self Build</option>
                <option value="other">Other</option>
            </select>
            </td>
        </tr>

        <tr>
            <td valign="top">
                <label for="enquiry">Enquiry *</label>
            </td>
            <td valign="top">
                <textarea name="enquiry" cols="25" rows="6" required></textarea>
            </td>
        </tr>

        <tr>
            <td colspan="2" style="text-align:center">
                <input type="submit" name="submit" value="Enquire" />
            </td>
        </tr>

        </table>
    </div>
</form>

php.ini

[mail function]
SMTP= smtp.gmail.com
smtp_port=587
sendmail_from = myemail@gmail.com
sendmail_path = "\"C:\Users\claire\Desktop\XAMPP\sendmail\sendmail.exe\" -t"

sendmail.ini

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username= myemail@gmail.com
auth_password= **********
force_sender = myemail@gmail.com

Any help would be greatly appreciated- feels like I've tried everything! Thanks

Claire
  • 1
  • 2
  • did you restart apache after setting these? – Masivuye Cokile May 25 '17 at 14:19
  • See my answer [here](https://stackoverflow.com/questions/42001769/sending-email-in-php-using-localhost/42002452#42002452) – Masivuye Cokile May 25 '17 at 14:20
  • @MasivuyeCokile yea I did - still not working. I have done exactly what's in your answer and still not working. However when I changed compatibility of sendmail.exe a 'User Account Control message appears stating do you want to allow the following program from an unknown publisher to make changed to this computer' -- also I echoed the mail function if successful and it echo's '1' . – Claire May 25 '17 at 14:26

0 Answers0