PHP电子邮件没有发送,有什么问题?

时间:2016-02-13 05:21:46

标签: php jquery email

我有一个html表单,信息被发送到这个脚本,一切都运行正常,除了发送的电子邮件...它似乎发送(如果声明通过)。但我没有收到任何东西。几天前我收到了电子邮件,其中所有数据都是"数组[]",但现在由于某种原因,它无法正常工作。

<?php
echo "<link href='https://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>";

if (!empty($_POST) && $_POST['email-address'] != null)
{
    $inquireType = $_POST['inquiry-type'];
    $firstName = $_POST['first-name'];
    $lastName = $_POST['last-name'];
    $email = $_POST['email-address'];
    $businessName = $_POST['business-name'];
    $information = $_POST['extra-information'];

    $message = "" . $inquireType . ' INQUIRIE FROM: ' . $firstName . ' ' . $lastName . "\r\n" .
        'Email: ' . $email . "\r\n" .
        'Business Name: ' . $businessName . "\r\n" .
        'Additional Information: ' . $information;

    $headers = "From: " . strip_tags($_POST['email-address']) . "\r\n";
    $headers .= "Reply-To: ". strip_tags($_POST['email-address']) . "\r\n";
    $headers .= "CC: bud@budbroesky.com\r\n";
    $headers .= "MIME-Version: 1.0\r\n";

    mail('myemail@gmail.com', "Inquirie", $message, $headers);

    if (mail('myemail@gmail.com', 'Inquirie From ' . $firstName, $message, $headers))
    {
        echo "<div style='position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: green;'><br><br><p align='center'><font size='5rem' face='Montserrat' color='white'>Inquiry Successfully Sent! Expect a reply from me shortly.";
    }
    else {
        echo "<div style='position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: red;'><br><br><p align='center'><font size='5rem' face='Montserrat' color='white'>Inquiry Not Sent, something must have went wrong...";
    }
}
else {
    echo "<div style='position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: darkred;'><br><br><p align='center'><font size='5rem' face='Montserrat' color='white'>Inquiry Not Sent, something must have went wrong...";
}

 ?>

2 个答案:

答案 0 :(得分:0)

变量$headers是一个字符串,您在发送电子邮件时使用implode("\r\n", $headers)。这将发出警告。

implode("\r\n", $headers)替换为$headers,因为您在准备标题字符串时已连接\r\n

答案 1 :(得分:0)

我认为是因为您没有提供电子邮件帐户的凭据。我在我的应用程序中使用了下面的代码(在C#中)。我希望它可以帮到你。

            //Configure an SmtpClient to send the mail.
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            client.EnableSsl = true; //only enable this if your provider requires it
            //Setup credentials to login to our sender email address ("UserName", "Password")
            NetworkCredential credentials = new NetworkCredential("mymail@gmail.com", "mypassword");
            client.Credentials = credentials;