Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php mail()不通过xampp发送电子邮件_Php_Html - Fatal编程技术网

php mail()不通过xampp发送电子邮件

php mail()不通过xampp发送电子邮件,php,html,Php,Html,我正在尝试创建一个html表单,可以将电子邮件发送到我的电子邮件地址,下面是我的html代码 <form method="post" name="myemailform" action="form-to-email.php"> <p> <label for='name'>Enter Name: </label><br> <input type="text" name="name"> </p> &l

我正在尝试创建一个html表单,可以将电子邮件发送到我的电子邮件地址,下面是我的html代码

<form method="post" name="myemailform" action="form-to-email.php">
<p>
    <label for='name'>Enter Name: </label><br>
    <input type="text" name="name">
</p>
<p>
    <label for='email'>Enter Email Address:</label><br>
    <input type="text" name="email">
</p>
<p>
    <label for='message'>Enter Message:</label> <br>
    <textarea name="message"></textarea>
</p>
<input type="submit" name='submit' value="submit">


输入名称:

输入电子邮件地址:

输入消息:


var frmvalidator=新的验证器(“myemailform”);
frmvalidator.addValidation(“名称”、“请求”、“请提供您的姓名”);
frmvalidator.addValidation(“电子邮件”、“请求”、“请提供您的电子邮件”);
frmvalidator.addValidation(“电子邮件”,“电子邮件”,“请输入有效电子邮件
地址);;
这是我的php代码

<?php
if(!isset($_POST['submit']))
{
    echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
if(empty($name)||empty($visitor_email))
{
    echo "Name and email are mandatory!";
    exit;
}
if(IsInjected($visitor_email))
{
    echo "Bad email value!";
    exit;
}
$email_from = &$visitor_email;
$email_subject = &$subject;
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".

$to = "a@gmail.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');


// Function to validate against any email injection attempts
function IsInjected($str)
{
    $injections = array('(\n+)',
                        '(\r+)',
                        '(\t+)',
                        '(%0A+)',
                        '(%0D+)',
                        '(%08+)',
                        '(%09+)'
                        );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if(preg_match($inject,$str))
    {
        return true;
    }
    else
    {
        return false;
    }
}
?> 

然而,当我在xampp中启动apache时,它没有发送电子邮件,我是否必须在real server中运行它,或者我的php代码有问题
任何类型的帮助都将不胜感激

这是在Windows系统上吗Xampp在本地主机中,我的意思是,您应该为SMPT打开一些端口;)一些合理的代码缩进将是一个好主意。它帮助我们阅读代码,更重要的是,它将帮助您为自己的利益调试代码。您可能会在几周/几个月内被要求修改此代码,最终您会感谢我。1)windows没有邮件服务器2)
mail()
不发送邮件3)all
mail()
是否将邮件传递到您可能没有的邮件服务器。因此,没有什么可以发送的邮件这是在mac系统上的,谢谢
<?php
if(!isset($_POST['submit']))
{
    echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
if(empty($name)||empty($visitor_email))
{
    echo "Name and email are mandatory!";
    exit;
}
if(IsInjected($visitor_email))
{
    echo "Bad email value!";
    exit;
}
$email_from = &$visitor_email;
$email_subject = &$subject;
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".

$to = "a@gmail.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');


// Function to validate against any email injection attempts
function IsInjected($str)
{
    $injections = array('(\n+)',
                        '(\r+)',
                        '(\t+)',
                        '(%0A+)',
                        '(%0D+)',
                        '(%08+)',
                        '(%09+)'
                        );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if(preg_match($inject,$str))
    {
        return true;
    }
    else
    {
        return false;
    }
}
?>