简体   繁体   English

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

[英]Why Won't My PHP Script Send Email?

Okay I'm working in jQuery mobile, and I just put in a PHP script for the email form. 好的,我正在使用jQuery mobile,我只是为电子邮件表单输入了PHP脚本。 Everything works great, except nothing is being sent to my inbox. 一切正常,除非什么都没有发送到我的收件箱。 Here is the form and php code, could really use some help here. 这是表格和php代码,在这里确实可以使用一些帮助。 Been scratching my brain for the longest. 最长的时间一直在挠我的大脑。

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

i didn't consider your html form as i believe your post method working fine and email.php getting all values as you set, here in my case i am assuming dummy values for checking you script, 我没有考虑您的html表单,因为我认为您的post方法可以正常工作,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"; if(mail($ to,$ subject,$ message,$ headers))回显“已发送的味精”; else echo 'There is no post information.'; 否则回显“没有职位信息”。

?> ?>

as i mentioned it before that i got the results but as spam for gmail, and working fine for other mailing servers; 正如我之前提到的,我得到了结果,但是对gmail却是垃圾邮件,对于其他邮件服务器也可以正常工作;

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM