简体   繁体   English

php mail()发送短信

[英]php mail() to send sms

I built a very small simple php() mail app to send sms messages to my staff from our portal. 我构建了一个非常小的简单php()邮件应用程序,通过我们的门户网站向我的员工发送短信。 Strange thing is, it was working fine this morning, tested it on and off for a couple of hours, everything was fine. 奇怪的是,它今天早上工作正常,开关测试了几个小时,一切都很好。 Then I left for the afternoon, came back and went back to make sure everything was still intact, and all of a sudden, the sms stopped working. 然后我离开了下午,回来后回去确保一切都完好无损,突然间,短信停止了工作。 Nothing was changed, the code was identical, I even re-uploaded the back-up I had from when it was working. 没有任何改变,代码是相同的,我甚至重新上传了我工作时的备份。 Here is what I know: 这就是我所知道的:

The send_sms.php works fine if I run it straight from the browser, I just get an empty message, but everything else is there. send_sms.php工作正常,如果我直接从浏览器运行它,我只是得到一个空消息,但其他一切都在那里。

I have additional scripts in the page to display an error or success message, which it doesn't do either of, also a snippet to clear the textarea when submitted, they have all stopped working. 我在页面中有其他脚本显示错误或成功消息,它不会执行任何操作,也是在提交时清除textarea的片段,它们都已停止工作。 I have researched this for hours, tried re-writing the send_sms.php, and the js, but can't get it to respond at all. 我已经研究了几个小时,尝试重写send_sms.php和js,但根本无法让它做出响应。 So here is what I have: 所以这就是我所拥有的:

HTML HTML

<form id="sendsms" name="sendsms" method="post" action="send_sms.php">
      <p>
        <textarea name="text" cols="45" rows="5" id="text" maxlength="130"  placeholder="Type your Text here, 130 characters max" required="required"> </textarea><div class="res4 text-muted" id="charNum"><small></small></div>
      </p>
<button type="submit" id="test" name="submit" class="btn btn-warning btn-    sm">Send SMS</button>
<div class="formsuccess" id="sendsmsResponse">

</div>
</form>

here is the js 这是js

 $("#sendsms").submit(function(event) 
 {
     event.preventDefault();

     var $form = $( this ),
         $submit = $form.find( 'button[type="submit"]' ),
         message_value = $form.find( 'textarea[name="text"]' ).val(),
         url = $form.attr('action');


     var posting = $.post( url, {                           
                       text: message_value

                   });

     posting.done(function( data )
     {

         $( "#sendsmsResponse" ).html(data);

         $submit.text('Your text was sent.');

         $submit.attr("disabled", true);

        $('#sendsms')[0].reset();

   setTimeout(function() {
       $('#sendsmsResponse').fadeOut();
       $('#text').val('')
       }, 10000 );

  function enableButton(){
      $('#test').attr("disabled", false);
      $('#test').text('Send Text');
}

 setTimeout(enableButton, 10500);


     });
});

and here is the mail script 这是邮件脚本

<?php

$text = $_POST['text'];


$to = "**********@vtext.com";
$subject = "Support";
$message = "$text";
$from = "*****@**********.net";
$headers = "From: $from";

if (mail($to,$subject,$message,$headers))


 {
        echo "<h5 class='alert alert-success res4'>Your text has been sent.     We will respond soon.</h5>";
    }

    else

  {
        echo "<h5 class='alert alert-danger res4'>Your text has NOT been     sent. Please try again.</h5>";
    }

?>

I just can't for the life of me figure out what happened to make it stop working, I have been trying to fix it for hours 我不能为我的生活弄清楚发生了什么让它停止工作,我一直试图修复它几个小时

I found the culprit, was just plain stupidity on my part. 我找到了罪魁祸首,对我来说只是简单的愚蠢。 I added a small login form to my nav header, which I have as a php include on the page with the text submit form, and it was using the same <button type="submit"> that I have on the sms form, as soon as I moved the login out of the header, everything worked fine. 我在我的导航标题中添加了一个小的登录表单,我在页面上有一个php包含文本提交表单,并且它使用的是我在短信表单上的<button type="submit"> ,如一旦我将登录名移出标题,一切正常。 I'm an idiot, thanks for your input, I'll be sure to look everywhere next time. 我是个白痴,谢谢你的投入,我一定会在下次到处看看。

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

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