简体   繁体   English

PHP邮件未发送消息

[英]PHP Mail Not Sending Messages

I realize this question title is pretty overused, but I couldn't find an answer to my problem. 我知道这个标题太用了,但是我找不到我的问题的答案。 This could be because either I'm not too good with PHP and I don't understand the problem, or because I have a different issue, but I thought I would post it and see if somebody can help me. 这可能是因为要么我对PHP不太满意,或者我不理解该问题,要么是因为我有一个不同的问题,但是我想我会发布它,看看是否有人可以帮助我。

I developed a website for a local church in my city and I made the site on my computer, put it onto my website as a sub directory and tested it all. 我为所在城市的当地教堂开发了一个网站,并在计算机上创建了该网站,并将其作为子目录放到我的网站上,并对其进行了全部测试。 It worked great. 效果很好。 One of the things the client wanted was there to be an email form that can send emails. 客户想要的一件事就是要有一个可以发送电子邮件的电子邮件表格。 I made it and all was good. 我做到了,一切都很好。

I then uploaded it onto the church server and thought it went good too. 然后,我将其上传到教堂服务器,并认为它也很好。 But then we decided to try the email form out, and for some reason it didn't work. 但是后来我们决定尝试发送电子邮件表格,由于某种原因,它不起作用。

I made the email form by having the user select a recipient (pastor, office manager, etc.) with a radio button, and that would change the action of the email form. 我通过使用户选择一个单选按钮来选择收件人(牧师,办公室经理等)来制作电子邮件表单,这将改变电子邮件表单的操作。 I just did something like this: 我只是做了这样的事情:

if (recipent == "pastor") {
    document.forms[0].action = "../scripts/php/pastor_contact.php";
} else if (recipent == "pastoralAssist") {
    document.forms[0].action = "../scripts/php/pastoral_assist_contact.php";    
} else if (recipent == "famMinistry") {
    document.forms[0].action = "../scripts/php/sacra_assist_contact.php";   
} else if (recipent == "sacraAssist") {
    document.forms[0].action = "../scripts/php/fam_ministry_contact.php";   
}

I know this isn't the cleanest, but it works great. 我知道这不是最干净的方法,但是效果很好。 The php files then, all look very similar to this (just a different email)" 然后,php文件看起来都与此非常相似(只是一封不同的电子邮件)”

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent="From: $name \n Email: $email \n Phone Number: $phone \n Message: $message";
$recipient = "email@example.com";
$subject = $_POST['subject'];
$mailheader = "$subject \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("There seems to be an error with this form. Sorry about the inconveince. We are working to get this fixed.");
header('Location: ../../quickylinks/message_sent.html') ;
?>

What this does, briefly, is collect the information from the email form, submit it as an email and then redirect the user to a "Message Sent" page. 简而言之,这是从电子邮件表单中收集信息,将其作为电子邮件提交,然后将用户重定向到“已发送邮件”页面。 This works on my server, but not theirs so I believe it's something to do with their server. 这适用于我的服务器,但不适用于他们的服务器,因此我认为这与他们的服务器有关。

You can see their server information here and mine here . 您可以在此处查看其服务器信息并 此处进行挖掘。

When the user sends the message, they get " There seems to be an error with this form. Sorry about the inconveince. We are working to get this fixed. " and the email doesn't go through, although the code is the same on my server and it works fine there. 当用户发送消息时,他们会收到“ 此表格似乎有误。对不起,抱歉。我们正在努力解决此问题。 ”尽管该代码是相同的,但电子邮件没有通过我的服务器,它在那里工作正常。

My initial thought was that PHP wasn't installed on their server (rare, but it does happen). 我最初的想法是没有在他们的服务器上安装PHP(很少,但是确实发生了)。 But it was. 但是确实如此。 So then I thought maybe it was installed, but the "mail" function was disabled. 因此,我以为可能已安装它,但是“邮件”功能被禁用了。 So I tried the following php code: 所以我尝试了以下php代码:

<?php 
if (function_exists('mail')) { 
    echo 'mail() is available'; 
} else { 
    echo 'mail() has been disabled'; }
?>

And it came back with "mail() is available". 它回来了,“ mail()可用”。

So now I'm stuck and I don't know the problem could be. 所以现在我被困住了,我不知道问题可能出在哪里。 As I said, I'm not very good at PHP yet so if somebody could give a detailed answer, I would be really really thankful! 就像我说的那样,我还不太擅长PHP,所以如果有人可以给出详细的答案,我将非常感谢!

Thank you so much! 非常感谢!

The server may not have mail program installed or configured properly. 服务器可能没有正确安装或配置邮件程序。 To see into what is going on and fix the issue on clients server, you will need root access to it, and you may need to ssh connect to their server to check / instal / configure what is neccessary . 要查看正在发生的情况并解决客户端服务器上的问题,您需要对其具有root访问权限,并且可能需要ssh连接到其服务器以检查/安装/配置必要的内容

First thing you should maybe do is to login with ssh to their server (not applicable if it is just a shared host, probably), and try php cli interface, and try out stuff. 您可能应该做的第一件事是使用ssh登录到他们的服务器(如果仅是共享主机,则可能不适用),然后尝试php cli接口,然后尝试一下。

If nothing works, you will need to try editing php.ini file on their server to inform php what program it should use for mailing. 如果没有任何效果,则需要尝试在其服务器上编辑php.ini文件,以通知php应该使用哪种程序进行邮寄。

If that doesnt give you anything, you will need to install & configure mail program , cause it probably doesnt work right on their server. 如果那没有给您任何帮助,则您需要安装和配置邮件程序 ,因为它可能无法在其服务器上正常工作。

EDIT: 编辑:

At first sight, their server has sendmail_path with no value at all. 乍一看,他们的服务器的sendmail_path毫无价值 It may mean that php has no clue thru which program it is supposed to send mail. 这可能意味着php无法确定应该通过哪个程序发送邮件。

Your settings, however, show that you have sendmail_path setting /usr/sbin/sendmail -t -i 但是,您的设置表明您具有sendmail_path设置/ usr / sbin / sendmail -t -i

So edit php.ini file on their server, sendmail_path (you need to know the path of sendmail program on their server, obviously) 因此,请在其服务器上编辑php.ini文件sendmail_path (显然,您需要知道其服务器上sendmail程序的路径)

Your production server is a Windows computer 您的生产服务器是Windows计算机

On the new server mail() is indeed available but is not configured. 在新服务器上,mail()确实可用,但未配置。

In order to be able to send an email from php you need to edit php.ini to use a smtp server. 为了能够从php发送电子邮件,您需要编辑php.ini以使用smtp服务器。

Your development server, a Linux server, is already configured properly. 您的开发服务器(Linux服务器)已经正确配置。 Your production server is a Windows computer that needs to be configured to send emails(edit the php.ini). 您的生产服务器是一台Windows计算机,需要对其进行配置以发送电子邮件(编辑php.ini)。 By default Windows doesn't come with an built in email server so you will have to install one or use the one provided by your ISP. 默认情况下,Windows不附带内置的电子邮件服务器,因此您必须安装一个或使用ISP提供的电子邮件服务器。

I strongly recommend you to use the PHPMailer class instead of the mail() function. 我强烈建议您使用PHPMailer类,而不要使用mail()函数。

You can easily configure an smtp server (like the one of your client) and use it to send emails. 您可以轻松配置smtp服务器(例如您的客户端之一)并使用它发送电子邮件。

Look at the test_smtp_basic.php example for more information. 查看test_smtp_basic.php示例以获取更多信息。

From this "You can see their server information here" your server does not have sendmail path 通过此"You can see their server information here"您的服务器没有sendmail路径 在此处输入图片说明

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

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