邮件功能无法在XAMPP localhost上运行

时间:2017-05-25 14:10:38

标签: php email xampp localhost

我正在创建'获取价格查询'表格使用HTML和PHP。但是,我的网站并不存在,所以我正在使用 XAMPP服务器 - localhost

我一直在搜索许多教程,更改了php.ini和sendmail.ini文件,更改了与Windows XP(Service Pack 3)的兼容性,但仍未找到解决方案。

当按下提交按钮但没有电子邮件进入我的Gmail帐户时,电子邮件说明没有错误。

PriceRequest.php - 发布表格

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 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

任何帮助都会非常感激 - 感觉就像我已经尝试过一切!感谢

0 个答案:

没有答案