[PHP Warning: mail(): “ sendmail_from” not set in php.ini or custom “From:” header missing

后端 未结 4 1292
挽巷
挽巷 2020-11-30 09:22

I am trying to use PHP\'s mail() function to send a test mail.

$to = \"****@gourab.me\";
$sub = \"Php Mail\";
$msg = \"Test Message From PHP\";

mail($to, $s         


        
相关标签:
4条回答
  • 2020-11-30 09:31
    <?php
    $to = "somebody@example.com";
    $subject = "My subject";
    $txt = "Hello world!";
    $headers = "From: webmaster@example.com" . "\r\n" .
    "CC: somebodyelse@example.com";
    
    mail($to,$subject,$txt,$headers);
    ?>
    
    0 讨论(0)
  • 2020-11-30 09:34
    <?php
    if(isset($_POST['send'])){
         $from =  $_POST['femail'];
         $phoneno = $_POST['phoneno'];
         $message = $_POST['message'];
         $carrier = $_POST['carrier'];
         if(empty($from)){
           echo("enter the email");
           exit();
    
         } 
    else if(empty($phoneno)){
       echo("enter the phone no");
         exit();
       }
     elseif(empty($carrier)){
       echo("enter the specific carrier");
       exit();
        }
     else if(empty($message)){
      echo("enter the message");
      exit();
      }
      else{
         $message = wordwrap($message, 70);
         $header = $from;
         $subject = 'from submission';
         $to = $phoneno.'@'.$carrier;
         $result = mail($to, $subject, $message, $header);
         echo("message sent to".$to);
    
      }
    
      }
    ?>
    
    0 讨论(0)
  • 2020-11-30 09:55

    Bro it seems that you're using you own PC/localhost/127.0.0.1 server that's why you can't connect to SMTP server. You can only send mail from live server using similar coding with some amendments :) i.e. add one parameter "Header/From".

    mail("You@me.com","Answer","Hope You Vote My Answer Up","From: me@you.com");
    
    0 讨论(0)
  • 2020-11-30 09:56

    It seems your From header is not correctly formatted. Try this instead:

    $headers =  'MIME-Version: 1.0' . "\r\n"; 
    $headers .= 'From: Your name <info@address.com>' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
    
    mail($to, $subject, $body, $headers);
    
    0 讨论(0)
提交回复
热议问题