douzhang1115 2012-03-06 19:16
浏览 29

PHP - SMTP身份验证

I've recently run in to mail problems with a wordpress theme contact form since php mail has been disabled on my shared server.

How can I modify this sendmail.php script to use SMTP authentication and bring it back to life?

http://pastebin.com/Besqc32E

  <?php

    if(isset($_POST['submit'])) {

      error_reporting(E_NOTICE);

      function valid_email($str)

      {

      return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;

         }

      if($_POST['name']!='' && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && strlen($_POST['comment'])>1)

      {

          $to = preg_replace("([
])", "", $_POST['receiver']);

          $from = preg_replace("([
])", "", $_POST['email']);

          $subject = "Website contact message from ".$_POST['name'];

          $message = $_POST['comment'];



          $match = "/(bcc:|cc:|content\-type:)/i";

            if (preg_match($match, $to) ||

                preg_match($match, $from) ||

                preg_match($match, $message)) {

              die("Header injection detected.");

            }

          $headers = "From: ".$from."
";

          $headers .= "Reply-to: ".$from."
";



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

          {

              echo 1; //SUCCESS

          }

          else {

              echo 2; //FAILURE - server failure

          }

      }

      else {

      echo 3; //FAILURE - not valid email



      }

      }else{

         die("Direct access not allowed!");

       }



  ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题
    • ¥20 RL+GNN解决人员排班问题时梯度消失
    • ¥60 要数控稳压电源测试数据
    • ¥15 能帮我写下这个编程吗