繁体   English   中英

我没有收到邮件php

[英]I am not receiving mail php

我收到邮件有问题。 我尝试了不同的邮件提供商(Microsoft,Yahoo,Gmail),但仍然没有收到邮件。 我正在为我的朋友在网站上工作,我用php联系人购买了一个引导模板。

我正在使用xampp,并且尝试过以这种方式发送邮件,但已将其上传到子文件夹中的其他一些朋友网站上,但仍然没有收到它。

这是代码:HTML index.php

<form class="js-contact-form" role="form" action="mail/contact.php" method="post" data-parsley-validate>
                        <div id="msgInfo"></div>
                        <input type="text" class="form-control wow fadeInLeft name" data-wow-delay="0.2s" placeholder="Name" required data-parsley-error-message="Enter name">
                        <input type="email" class="form-control wow fadeInLeft email" data-wow-delay="0.4s" placeholder="Email" required data-parsley-error-message="Enter email">
                        <textarea class="form-control wow fadeInLeft message" data-wow-delay="0.6s" rows="6" placeholder="Message" required data-parsley-error-message="Enter message"></textarea>
                        <button type="submit" class="btn btn-lg wow fadeInUp" data-wow-delay="1s">Send message</button>
    </form>

这是contact.php代码:

<?php
// PHP script for sending email
//
// Configuration
//

$toEmail = "";                                          // replace with your email where you would like to send email
$subject = 'Contact form from my website';              // replace with subject you want to receive
$body    = 'You have received email from website:';     // replace with text that you want to receive in email
$from    = '';                                          // replace with email that will look like sender

//
// ----- do not edit after this line if you don't understand what you are doing -----
//

if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message']) ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
    echo "Invalid input";
    return false;
}

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$body .= "\n";
$body .= "Name: $name\n";
$body .= "Email: $email\n";
$body .= "Message: $message\n";

$headers = "From: $email\n";
$headers .= "Reply-To: $toEmail";

$res = mail($toEmail, $subject, $body, $headers);
echo "OK";
return true;
?>

这不是我第一次使用php,过去我曾经使用过php(2-3年前),并且我也对此进行了测试,但是它不起作用-.-

有人能帮助我吗。

您必须为表单中的所有输入/文本标记添加名称属性,以便可以在$ _POST数组中找到它们

<form class="js-contact-form" role="form" action="mail/contact.php" method="post" data-parsley-validate>
                    <div id="msgInfo"></div>
                    <input type="text" class="form-control wow fadeInLeft name" data-wow-delay="0.2s" placeholder="Name" required data-parsley-error-message="Enter name" name="name">
                    <input type="email" class="form-control wow fadeInLeft email" data-wow-delay="0.4s" placeholder="Email" required data-parsley-error-message="Enter email" name="email">
                    <textarea class="form-control wow fadeInLeft message" data-wow-delay="0.6s" rows="6" placeholder="Message" required data-parsley-error-message="Enter message" name="message"></textarea>
                    <button type="submit" class="btn btn-lg wow fadeInUp" data-wow-delay="1s">Send message</button>
</form>

并在您的php代码中更改此行($ ToEmail变量始终为空)

$res = mail($toEmail, $subject, $body, $headers);

有了这个

$res = mail($email, $subject, $body, $headers);

尝试替换为

$body .= "\n";
$body .= "Name: ".$name."\n";
$body .= "Email: ".$email."\n";
$body .= "Messagee: ".$message."\n";

并更改标题:

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers = 'From: '.$name."\r\n".'Reply-To: '.$email."\r\n".'X-Mailer: PHP/' . phpversion();


更新资料

if($res){
echo "OK";
}
else{
echo "failed."

}

这样,您可以知道您的邮件是否正常工作。
如果未启用,则启用php中的错误:

ini_set('display_errors',1);

暂无
暂无

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

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