简体   繁体   English

PHP中的邮件功能无法通过发送

[英]Mail function in php not sending through

My Php code originally sent through an email, using this exact function however now i have tried to alter the header so the email didnt come through as @backend1.freehosting.com and the function does not work. 我的Php代码最初是通过电子邮件发送的,使用的是确切的功能,但是现在我尝试更改标题,因此电子邮件没有通过@ backend1.freehosting.com进入,并且该功能无法正常工作。

My code is: 我的代码是:

<?php
    // display form if user has not clicked submit
    if (!isset($_POST["submit"])) {
?>
    <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
        From: <input type="text" name="from"><br>
        Email: <input type="text" name="email"><br>
        Subject: <input type="text" name="subject"><br>
        Message: <textarea rows="10" cols="40" name="message"></textarea><br>
        <input type="submit" name="submit" value="Submit Feedback">
    </form>
<?php 
    }else {
        // the user has submitted the form
        // Check if the "from" input field is filled out
        if (isset($_POST["from"])) {
            $from = $_POST["from"]; // sender
            $subject = $_POST["subject"];
            $message = $_POST["message"];
            // message lines should not exceed 70 characters (PHP rule), so wrap it
            $message = wordwrap($message, 70);
            // send mail
            $headers = 'From: me@mysitedomain.com' . "\r\n" .
            'Reply-To: me@mysitedomain.com' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
            mail("example@hotmail.com",$subject,$message,$headers);
            echo "Thank you for sending us feedback";
        }
    }
?>

Usually, mail log including errors are sent to your systems mail server log directory. 通常,包含错误的邮件日志将发送到系统邮件服务器日志目录。 If you are using CentOS / RHEL / Redhat or Fedora Linux, check /var/log/maillog file using any one of the following command: 如果您使用的是CentOS / RHEL / Redhat或Fedora Linux,请使用以下任一命令检查/var/log/maillog文件:

NOTE: Needs to have ssh access on the server 注:需要在服务器上具有ssh访问

tail -f /var/log/maillog

grep 'user@example.com' /var/log/maillog

more /var/log/maillog

If you are using Ubuntu or Debian Linux, check /var/log/mail.err and /var/log/mail.log files: 如果您使用的是Ubuntu或Debian Linux,请检查/var/log/mail.err/var/log/mail.log文件:

tail -f /var/log/mail.log

tail -f /var/log/mail.err

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

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