我有一个 html 表单,其中包含发送到此脚本的信息,除了发送电子邮件外,一切都运行良好......它似乎正在发送(如果语句通过)。但我什么也没收到。几天前,我收到电子邮件,其中所有数据都是"Array[]",但现在由于某种原因它不起作用。
<?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...";
}
?>
变量$headers
是一个字符串,您在发送电子邮件时使用implode("'r'n", $headers)
。这将引发警告。
将implode("'r'n", $headers)
替换为$headers
,因为在准备标头字符串时已经连接了'r'n
。
我认为
这是因为您没有提供电子邮件帐户的凭据。我已经在我的应用程序中使用了下面的代码(在 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;