为什么我的PHP脚本不会发送电子邮件?

时间:2012-03-29 09:27:37

标签: php jquery-mobile contact-form

好的我正在使用jQuery mobile,我只是为电子邮件表单添加了一个PHP脚本。一切都很好,除了没有任何东西被发送到我的收件箱。这里是表单和php代码,可以在这里真正使用一些帮助。一直在抓我的大脑最长。

<?php
if($_SERVER['REQUEST_METHOD'] == "POST") 
{
    $message_body = 'First Name: ' . $_POST['firstName'] . '
            Last Name: ' . $_POST['lastName'] . '
            Email: ' . $_POST['email'] . '
            Company: ' . $_POST['company'] . '
            Phone: ' . $_POST['phone'] . '
            Services: ' . $_POST['serviceAreas'] .'
            Message: ' . $_POST['comments'];

    $to      = 'marvin.fai2@gmail.com';
    $subject = 'MobilizeWorldwide.com Contact Submission';
    $message = $message_body;
    $headers = 'From: info@mobilizeworldwide.com' . "\r\n" .
            'Reply-To: ' . $_POST['email'] . "\r\n" .
            'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);

    header('Location: ' . $_POST['thankspage']);
}
else
{
    echo 'There is no post information.';
}

HTML:

 <form method="post" action="email.php">
          <input type="text" name="firstName" placeholder="First name" required>
          <input type="text" name="lastName" placeholder="Last name" required>
          <input type="text" name="email" placeholder="Email Address" required>
          <input type="text" name="company" placeholder="Company">
          <input type="text" name="phone" placeholder="Phone Number">
          <fieldset>
            <legend>Please indicate service areas of interest, and select all that apply:</legend>
            <input id="airFrame" name="serviceArea" type="checkbox">
            <label for="airFrame">VISA</label>
            <input id="compMaint" name="serviceArea" type="checkbox">
            <label for="compMaint">AmEx</label>
            <input id="engineAPU" name="serviceArea" type="checkbox">
            <label for="engineAPU">Mastercard</label>
            <input id="engineAPULeas" name="serviceArea" type="checkbox">
            <label for="engineAPULeas">VISA</label>
            <input id="lMaint" name="serviceArea" type="checkbox">
            <label for="lMaint">AmEx</label>
            <input id="gTS" name="serviceArea" type="checkbox">
            <label for="gTS">Mastercard</label>
            <input id="onW" name="serviceArea" type="checkbox">
            <label for="onW">VISA</label>
            <input id="train" name="serviceArea" type="checkbox">
            <label for="train">AmEx</label>
          </fieldset>
          <textarea id="comments" name="comments" placeholder="Comments" rows="8"></textarea>
          <button type="submit" value="Submit" name="submit">
        </form>

1 个答案:

答案 0 :(得分:0)

我没有考虑你的html表格,因为我相信你的帖子方法工作正常,而email.php获取你设置的所有值,在我的情况下,我假设用于检查脚本的虚拟值,

<?php

$message_body = 'First Name: ' . "tariq" . '
        Last Name: ' . "sarwar" . '
        Email: ' . "mts@gmail.com" . '
        Company: ' . "renai" . '
        Phone: ' . "123456" . '
        Services: ' . "abcdef" .'
        Message: ' . "Test message" ;

$to      = 'mtarik.sarwar@gmail.com';
$subject = 'MobilizeWorldwide.com Contact Submission';
$message = $message_body;
$headers .= 'From: "user" <user@domain.com>' . "\r\n";

if(mail($ to,$ subject,$ message,$ headers))    echo“msg sent”; 其他     echo'没有帖子信息。';

&GT;

正如我之前提到的那样,我得到了结果,但作为gmail的垃圾邮件,并且对其他邮件服务器工作正常;

enter image description here