복붙노트

어떤 이유로 PHP 메일이 작동하지 않습니다.

PHP

어떤 이유로 PHP 메일이 작동하지 않습니다.

나는 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.";
    }
?>

아무것도 놓친 건지,이 함수에 대한 파일을 포함해야합니까 .. 나는 asp.net에서 & 이것은 웹 사이트에서 발견 된 기본 스크립트입니다.

나는 메일들과 관련된 다른 스크립트들도 시도해 보았다.

나는 로컬 호스트가 아닌 웹 사이트에서이 스크립트를 실행하고 있습니다.

해결법

  1. ==============================

    1.이것은 아마도 구성 오류입니다. PHP 메일 기능을 사용하려면 php.ini를 편집해야합니다.

    이것은 아마도 구성 오류입니다. PHP 메일 기능을 사용하려면 php.ini를 편집해야합니다.

    더 쉽고 다재다능한 옵션을 찾고 있다면 (필자 의견으로는) PHPMailer를 사용해야한다.

  2. ==============================

    2.우분투를 사용하고 있고 sendmail이 / usr / sbin / sendmail에없는 것 같으면 다음 명령으로 터미널을 사용하여 sendmail을 설치하십시오.

    우분투를 사용하고 있고 sendmail이 / usr / sbin / sendmail에없는 것 같으면 다음 명령으로 터미널을 사용하여 sendmail을 설치하십시오.

    sudo apt-get install sendmail
    

    mail ()이 작성된 PHP 페이지를 다시 실행하십시오. 또한 스팸 폴더를 확인하십시오.

  3. ==============================

    3.이것은 php.ini 파일에있는 SMTP 설정의 문제 일 수 있습니다.

    이것은 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 메일 기능을 사용하십시오.

  4. ==============================

    4."이메일을 보낸다고해서 도착할 것이라는 의미는 아닙니다."

    "이메일을 보낸다고해서 도착할 것이라는 의미는 아닙니다."

    심각한 메일 - 예 : "보낸 사람 :"주소로 사용하고있는 도메인이 웹 서버의 전자 메일을 거부하도록 구성되었을 수 있습니다. 더 긴 개요 및 확인할 사항에 대한 정보는 http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html을 참조하십시오.

  5. ==============================

    5.우편 기능은 실제 우편 배달을 보장하지 않습니다. 메시지를 외부 프로그램 (보통 sendmail)에 전달하는 것뿐입니다. 이 기능을 사용하려면 올바르게 구성된 SMTP 서버가 필요합니다. 또한 SMTP 인증을 지원하지 않습니다. SwiftMailer의 PEAR :: Mail 라이브러리를 확인해보십시오. 둘 다 더 많은 옵션을 제공합니다.

    우편 기능은 실제 우편 배달을 보장하지 않습니다. 메시지를 외부 프로그램 (보통 sendmail)에 전달하는 것뿐입니다. 이 기능을 사용하려면 올바르게 구성된 SMTP 서버가 필요합니다. 또한 SMTP 인증을 지원하지 않습니다. SwiftMailer의 PEAR :: Mail 라이브러리를 확인해보십시오. 둘 다 더 많은 옵션을 제공합니다.

  6. ==============================

    6.php.ini 파일에서 SMTP 설정을 확인하십시오. 호스트는 사용할 자격 증명에 대한 문서를 가지고 있어야합니다. 아마도 오류 로그 파일을 검사 할 수 있으며 더 많은 정보를 얻을 수 있습니다.

    php.ini 파일에서 SMTP 설정을 확인하십시오. 호스트는 사용할 자격 증명에 대한 문서를 가지고 있어야합니다. 아마도 오류 로그 파일을 검사 할 수 있으며 더 많은 정보를 얻을 수 있습니다.

  7. ==============================

    7.HostGator의 경우 헤더에 다음을 사용해야합니다.

    HostGator의 경우 헤더에 다음을 사용해야합니다.

    $headers = 'From: user@yourdomain.com' . " " .
    'Reply-To: user@yourdomain.com' . " " .
    'X-Mailer: PHP/' . phpversion();
    

    응답자가 다른 것일 수 있지만 보낸 사람이 전자 메일을 호스트 한 경우에만 나를 위해 일했습니다. 보낸 사람 : owner@domain.com, 답장 : info@domain.com

    http://support.hostgator.com/articles/specialized-help/technical/php-email-from-header http://support.hostgator.com/articles/specialized-help/technical/how-to-use-sendmail-with-php

  8. ==============================

    8.나는 이것을 잠시 동안 사용하고 있는데, 이것이 실제 PHP 버전에서 여전히 최신인지는 모르겠다. 이 파일을 하나의 파일 설정에서 사용하거나 contact.php와 index.php와 같은 두 파일로 나눌 수 있습니다.

    나는 이것을 잠시 동안 사용하고 있는데, 이것이 실제 PHP 버전에서 여전히 최신인지는 모르겠다. 이 파일을 하나의 파일 설정에서 사용하거나 contact.php와 index.php와 같은 두 파일로 나눌 수 있습니다.

    <?php 
    error_reporting(E_ALL ^ E_NOTICE); 
    
    
    if(isset($_POST['submitted'])) {
    
    
    if(trim($_POST['contactName']) === '') {
        $nameError =  '<span style="margin-left:40px;">You have missed your name.</span>'; 
        $hasError = true;
    } else {
        $name = trim($_POST['contactName']);
    }
    
    if(trim($_POST['topic']) === '') {
        $topicError = '<span style="margin-left:40px;">You have missed the topic.</span>'; 
        $hasError = true;
    } else {
        $topic = trim($_POST['topic']);
    }
    
    $telefon = trim($_POST['phone']);
    $company = trim($_POST['company']);
    
    
    if(trim($_POST['email']) === '')  {
        $emailError = '<span style="margin-left:40px;">You have missed your email adress.</span>';
        $hasError = true;
    } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
        $emailError = '<span style="margin-left:40px;">You have missspelled your email adress.</span>';
        $hasError = true;
    } else {
        $email = trim($_POST['email']);
    }
    
    
    if(trim($_POST['comments']) === '') {
        $commentError = '<span style="margin-left:40px;">You have missed the comment section.</span>';
        $hasError = true;
    } else {
        if(function_exists('stripslashes')) {
            $comments = utf8_encode(stripslashes(trim($_POST['comments'])));
        } else {
            $comments = trim($_POST['comments']);
        }
    }
    
    
    if(!isset($hasError)) {
    
        $emailTo = 'info@example.com';
        $subject = 'Example.com - '.$name.' - '.$betreff;
        $sendCopy = trim($_POST['sendCopy']);
        $body = "\n\n This is an email from http://www.example.com \n\nCompany : $company\n\nName : $name \n\nEmail-Adress : $email \n\nPhone-No.. : $phone \n\nTopic : $topic\n\nMessage of the sender: $comments\n\n";
        $headers = "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n";
    
        mail($emailTo, $subject, $body, $headers);
    
    
    
        $emailSent = true;
    }
    }
    ?>
    
    }
    .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>
    
  9. from https://stackoverflow.com/questions/8803994/php-mail-not-working-for-some-reason by cc-by-sa and MIT license