php mail function

前端 未结 5 700
夕颜
夕颜 2020-12-20 08:53


        
相关标签:
5条回答
  • 2020-12-20 09:45

    Basically is hard to send a mail from localhost to any mail providers. They have big restrictions on the incoming mails, and the simply mail() won't work.

    You need to use an SMTP server. and define that server in php configuration

    smtp = localhost  #(here should be your smtp server)
    smtp_port = 25
    

    if you don't have an SMTP server, try to pass all headers like in PHP examples:

    $to      = 'nobody@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: webmaster@example.com' . "\r\n" .
        'Reply-To: webmaster@example.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    
    mail($to, $subject, $message, $headers);

    http://www.php.net/manual/en/function.mail.php

    0 讨论(0)
  • 2020-12-20 09:45

    Try this:

    <?php
        $sender = 'email@example.com';
        $recipient = 'email@example.com';
        $subject = "php mail test";
        $message = "php test message";
        $headers = 'From:' . $sender;
        if (mail($recipient, $subject, $message, $headers))
        {
            echo "Message accepted";
        }
        else
        {
            echo "Error: Message not accepted";
        }
    ?>
    
    0 讨论(0)
  • 2020-12-20 09:54
     <?php
       $name = $_POST['name'];
        $visitor_email = $_POST['email'];
       $message = $_POST['message'];
     ?>
     <?php
      $email_from = 'yourname@yourwebsite.com';
    
      $email_subject = "New Form submission";
    
      $email_body = "You have received a new message from the user $name.\n".
                            "Here is the message:\n $message"
     ?>
     <?php
    
     $to = "inspiretechpark@gmail.com";
    
     $headers = "From: $email_from \r\n";
    
     $headers .= "Reply-To: $visitor_email \r\n";
    
     mail($to,$email_subject,$email_body,$headers);
    
     ?>
     <?php
     $to = "name1@website-name.com, name2@website-name.com,name3@website-
     name.com";
    
      mail($to,$email_subject,$email_body,$headers);
      ?>
    <?php
     $to = "name1@website-name.com, name2@website-name.com,name3@website-
     name.com";
    
      $headers = "From: $email_from \r\n";
    
      $headers .= "Reply-To: $visitor_email \r\n";
    
      $headers .= "Cc: someone@domain.com \r\n";
    
      $headers .= "Bcc: someoneelse@domain.com \r\n";
    
      mail($to,$email_subject,$email_body,$headers);
      ?>
    

    Try This Guys..This Is For Sending Mail

    0 讨论(0)
  • 2020-12-20 09:55

    You need to make sure that you have your PHP installation set up to use a working SMTP Server. You might find what you're looking for in answers to this question. Failing that you'll likely need to test your script on your live web server.

    0 讨论(0)
  • 2020-12-20 09:56

    If you are working with localhost then, i hope it will never work. It will work only on a mail configured server. Please try on it.

    0 讨论(0)
提交回复
热议问题