0

I try to send email from my program to user.

here code:

public function send_mail(){
     $to = "mail@ymail.com";
     $subject = "This is subject";

     $message = "<b>This is HTML message.</b>";
     $message .= "<h1>This is headline.</h1>";

     $header = "From:abc@somedomain.com \r\n";
     $header = "Cc:afgh@somedomain.com \r\n";
     $header .= "MIME-Version: 1.0\r\n";
     $header .= "Content-type: text/html\r\n";

     $retval = mail ($to,$subject,$message,$header);

     if( $retval == true )
     {
        echo "Message sent successfully...";
     }
     else
     {
        echo "Message could not be sent...";
     }
}

the message always say message send successfully, but never sent into my inbox. please some one can help me to solve this?

  • Did you check your spam box? If the header does not match the actual server address that you send the email from, most email clients mark it as spam. – Niki van Stein Nov 17 '15 at 09:22
  • 3
    Afaik when `mail()` comes back with true, it's handed it over to an MTA at which point it's no longer PHP's concern. – Jonnix Nov 17 '15 at 09:23
  • @BasvanStein van stein: yes i check spam and still get nothing, i try with 2 different email and still get nothing. – Panji Syndrome Nov 17 '15 at 09:25
  • @JonStirling : can you give me more specific? – Panji Syndrome Nov 17 '15 at 09:26
  • @PanjiSyndrome Not really. The e-mail has been passed over to another service separate from PHP, so it really depends on your server setup. – Jonnix Nov 17 '15 at 09:49

2 Answers2

1

If the return value of the mail() function is "true", then it means the message has been accepted for delivery. So your php code seems okay.

But by whom is your email accepted ? The server where your script is running must be configured to send the email further.

See here for ubuntu: http://ubuntuforums.org/showthread.php?t=780509

Bar-code
  • 277
  • 1
  • 6
0

The PHP mail() command hands the message off to the local MTA running on the server, which (should) then deliver the message to the recipient's MX. If the message is not being received at the recipient's MX, then you should check the local MTA's logs to see if: (1) The message was received from PHP, and (2) what happened when the message was attempted for delivery to the recipient's MX.

mti2935
  • 11,465
  • 3
  • 29
  • 33