PHP Mail To什么都不做



我有一些HTML/PHP代码。当我把它上传到我的网站时,点击发送电子邮件按钮,它就在那里。。。。为什么?

HTML

<form class="contact-form" action="contactform.php" method="post"></form>
<input type="text" name="name" placeholder="Full Name">
<input type="text" name="mail" placeholder="Your e-mail address">
<input type="text" name="subject" placeholder="Subject">
<textarea name="message" placeholder="Message"></textarea>
<button type="submit" name="submit">SEND MAIL</button>
</form>

PHP

<?php
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "Support@Kentuckianabowler.com";
$headers = "From: ".$mailFrom;
$txt = "You have received an e-mail from ".$name.".nn".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html?mailsend");
}
?>

正如@pr1nc3所说,通过在if语句中执行var_dump($_POST),确保变量首先存在,如果所有变量都存在,请尝试以下操作:

$uid = md5(uniqid(time()));
$headers = "From: " . $mailFrom . "rn";
$headers .= "Reply-To: " . $mailFrom . "rn";
$headers .= "MIME-Version: 1.0" . "rn";
$headers .= "Content-Type: multipart/mixed; boundary="".$uid.""rn";
$txt= "--".$uid."rn";
$txt.= "Content-type:text/html; charset=UTF-8" . "rn";
$txt.= "You have received an e-mail from ".$name.".nn".$message;
mail($mailTo, $subject, $txt, $headers);

您可以使用sendmail包从localhost发送邮件,sendmail包在XAMPP中内置。因此,如果您使用XAMPP,那么您可以轻松地从localhost发送邮件。

例如,您可以为gmail配置C:\xamp\php\php.ini和C:\xamp\sendmail\sendmail.ini来发送邮件。

在C:\examplep\php\php.ini中查找extension=php_opensl.dll并删除该行开头的分号,以使SSL适用于localhost的gmail。

在php.ini文件中找到[邮件功能]并更改

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = ""C:xamppsendmailsendmail.exe" -t"

现在打开C:\examplep\sendmail\sendmail.ini。用以下代码替换sendmail.ini中的所有现有代码

[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com

现在你完成了!!使用mail功能创建php文件并从localhost发送邮件。

附言:别忘了在上面的代码中替换我的gmail id和gmail密码。此外,如果您从上面复制了设置,请不要忘记删除重复的密钥。例如,如果存在另一个sendmail_path,请在下面一行注释:sendmail_path=php.ini文件中的"C:\examplep\mailtodisk\mailtodisk.exe">

还记得使用XAMMP控制面板重新启动服务器,以便更改生效。

对于gmail,请检查https://support.google.com/accounts/answer/6010255以允许来自不太安全的应用程序的访问。

最新更新