Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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邮件由于某些原因无法工作_Php - Fatal编程技术网

PHP邮件由于某些原因无法工作

PHP邮件由于某些原因无法工作,php,Php,我是PHP新手,我正在使用mail函数发送不起作用的电子邮件。我收到了一条成功的信息,但它仍然不起作用 相同代码 <?php $email_to = "abc@abc.com"; $email_subject = "Test mail"; $email_body = "Hello! This is a simple email message."; if(mail($email_to, $email_subject, $email_body)){

我是PHP新手,我正在使用mail函数发送不起作用的电子邮件。我收到了一条成功的信息,但它仍然不起作用

相同代码

<?php
    $email_to = "abc@abc.com";
    $email_subject = "Test mail";
    $email_body = "Hello! This is a simple email message.";


    if(mail($email_to, $email_subject, $email_body)){
        echo "The email($email_subject) was successfully sent.";
    } else {
        echo "The email($email_subject) was NOT sent.";
    }
?>

如果我遗漏了什么,我是否需要包含此函数的任何文件。。我来自asp.net&这是在网站上找到的基本脚本

我尝试了其他与邮件相关的脚本,它们也不起作用


我在网站上运行此脚本,而不是在本地主机上运行此脚本这可能是配置错误。如果您坚持使用PHP
mail
函数,则必须编辑
PHP.ini


如果您正在寻找一个更简单、更通用的选项(在我看来),您应该使用。

检查php.ini文件中的SMTP设置。您的主机应该有一些关于使用哪些凭据的文档。也许您可以检查错误日志文件,它可能有更多可用信息。

邮件功能不能保证邮件的实际送达。它所做的只是将消息传递给外部程序(通常是sendmail)。您需要一个正确配置的SMTP服务器才能正常工作。还要记住,它不支持SMTP身份验证。您可以查看SwiftMailer的PEAR::Mail库,它们都为您提供了更多选择。

仅仅因为您发送了电子邮件并不意味着它会到达。


发送邮件是一项严肃的工作-例如,您使用的“发件人:”地址域可能会被配置为拒绝来自Web服务器的电子邮件。有关更详细的概述(以及一些要检查的提示),请参见

这可能是php.ini文件中SMTP配置的问题

由于您是PHP新手,因此可以在PHP安装文件夹的根目录中找到PHP.ini文件,并检查SMTP=和SMTP_port=并将值更改为

SMTP = your mail server e.g) mail.yourdomain.com
smtp_port = 25(check your admin for original port)

如果您的服务器发送邮件需要身份验证,请使用PEAR邮件功能。

如果您使用的是Ubuntu,并且sendmail似乎不在
/usr/sbin/sendmail
中,请使用以下命令使用终端安装sendmail:

sudo apt-get install sendmail

然后运行重新加载PHP页面,其中写入了
mail()
。同时检查您的垃圾邮件文件夹。

对于HostGator,您需要使用以下标题:

$headers = 'From: user@yourdomain.com' . " " .
'Reply-To: user@yourdomain.com' . " " .
'X-Mailer: PHP/' . phpversion();
它仅在“发件人”用户是主机电子邮件时对我有效,而“收件人”的回复可能与以下内容不同,例如:owner@domain.com,答复:info@domain.com


我现在正在使用它一段时间,不知道它是否仍然是实际PHP版本的最新版本。您可以在一个文件设置中使用它,或者将它拆分为两个文件,如contact.php和index.php

contact.php |代码

<?php
    $email_to = "abc@abc.com";
    $email_subject = "Test mail";
    $email_body = "Hello! This is a simple email message.";


    if(mail($email_to, $email_subject, $email_body)){
        echo "The email($email_subject) was successfully sent.";
    } else {
        echo "The email($email_subject) was NOT sent.";
    }
?>
index.php |表单代码


谢谢你的关注。您的电子邮件已发送!


电子邮件尚未发送。请检查联系表。

单位

检查您的配置在哪里使用?在本地计算机或服务器上?请与您的主机联系,许多主机已出于反垃圾邮件的目的禁用了mail()函数。您可能需要改用smtp。请更改您的服务器配置。并非每个服务器都可以用作MailServers脚本看起来正常。此外,Suces消息建议存在配置问题。。。检查您的配置。。。还要检查接收服务器上的配置。而且。。。有90%的几率那封邮件会变成垃圾邮件。。。也检查一下。给我修好了,谢谢。我被困在这上面好几个小时了。。这么简单的修复lol——只是补充一下,我使用的是
ovh
VPS。所以,如果将来有人看到这个,您好:)哇,问题解决了!我更改了标题,但它不起作用。现在修好了!!thnaksHow正在下载一大堆分布在8个文件夹中的文件,浏览文档,下载您需要的所有依赖项,设置所有依赖项以及它们的依赖项,等等,等等,应该比编辑ini文件更容易吗?
}
.formblock{display:block;padding:5px;margin:8px; margin-left:40px;}
.text{width:500px;height:200px;padding:5px;margin-left:40px;}
.center{min-height:12em;display:table-cell;vertical-align:middle;}
.failed{ margin-left:20px;font-size:18px;color:#C00;}
.okay{margin-left:20px;font-size:18px;color:#090;}
.alert{border:2px #fc0;padding:8px;text-transform:uppercase;font-weight:bold;}
.error{font-size:14px;color:#C00;}

label
{
margin-left:40px;
}

textarea

{
margin-left:40px;
}
<?php header('Content-Type: text/html;charset=UTF-8'); ?>
<!DOCTYPE html>
<html lang="de">
<head>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>


<form action="contact.php" method="post">

<?php if(isset($emailSent) && $emailSent == true) { ?>

<span class="okay">Thank you for your interest. Your email has been send !</span>

<br>

<br>

<?php } else { ?>

<?php if(isset($hasError) || isset($captchaError) ) { ?>

<span class="failed">Email not been send. Please check the contact form.</span>

<br>

<br>

<?php } ?>

<label class="text label">Company</label>

<br>

<input type="text" size="30" name="company" id="company" value="<?php if(isset($_POST['company'])) echo $_POST['comnpany'];?>" class="formblock" placeholder="Your Company">

<label class="text label">Your Name <strong class="error">*</strong></label>

<br>

<?php if($nameError != '') { ?>

<span class="error"><?php echo $nameError;?></span>

<?php } ?>

<input type="text" size="30" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="formblock" placeholder="Your Name">

<label class="text label">- Betreff - Anliegen - <strong class="error">*</strong></label>

<br>

<?php if($topicError != '') { ?>

<span class="error"><?php echo $betrError;?></span>

<?php } ?>

<input type="text" size="30" name="topic" id="topic" value="<?php if(isset($_POST['topic'])) echo $_POST['topic'];?>" class="formblock" placeholder="Your Topic">

<label class="text label">Phone-No.</label>

<br>

<input type="text" size="30" name="phone" id="phone" value="<?php if(isset($_POST['phone'])) echo $_POST['phone'];?>" class="formblock" placeholder="12345 678910">

<label class="text label">Email-Adress<strong class="error">*</strong></label>

<br>

<?php if($emailError != '') { ?>

<span class="error"><?php echo $emailError;?></span>

<?php } ?>

<input type="text" size="30" name="email" id="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="formblock" placeholder="info@example.com">

<label class="text label">Your Message<strong class="error">*</strong></label>

<br>

<?php if($commentError != '') { ?>

<span class="error"><?php echo $commentError;?></span>

<?php } ?>

<textarea name="comments" id="commentsText" class="formblock text" placeholder="Leave your message here..."><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>

<button class="formblock" name="submit" type="submit">Send Email</button>
<input type="hidden" name="submitted" id="submitted" value="true">
<?php } ?>

</form>
</body>
</html>
<script type="text/javascript">

<!--//--><![CDATA[//><!--

$(document).ready(function() {

$('form#contact-us').submit(function() {

$('form#contact-us .error').remove();
var hasError = false;

$('.requiredField').each(function() {

if($.trim($(this).val()) == '') {
var labelText = $(this).prev('label').text();

$(this).parent().append('<br><br><span style="margin-left:20px;">You have missed '+labelText+'.</span>.');

$(this).addClass('inputError');
hasError = true;

} else if($(this).hasClass('email')) {

var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test($.trim($(this).val()))) {

var labelText = $(this).prev('label').text();

$(this).parent().append('<br><br><span style="margin-left:20px;">You have entered a wrong '+labelText+' adress.</span>.');

$(this).addClass('inputError');
hasError = true;
}
}
});
if(!hasError) {

var formInput = $(this).serialize();

$.post($(this).attr('action'),formInput, function(data){

$('form#contact-us').slideUp("fast", function() {                  
$(this).before('<br><br><strong>Thank You!</strong>Your Email has been send successfuly.');

});

});

}
return false;   

});

});

//-->!]]>

</script>