0

i have a code that should send mail in php using cpanel , I don't know why it is not working in Cpanel , it is not throwing error too , i gave try catch, but it is not catching any exception. Since am new to Cpanel. I am not able to understand what is the issue

<html>
   
   <head>
      <title>Sending HTML email using PHP</title>
   </head>
   
   <body>
      
      <?php
      try{
         $to = "name@doman1.com";
         $subject = "This is subject";
         
         $message = "<b>This is HTML message.</b>";
         $message .= "<h1>This is headline.</h1>";
         
         $header = "From:name2@gmail.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...";
        //  }
      }catch(Exception $e){
          echo "The error is ".$e;
      }
      ?>
      
   </body>
</html>

Can anyone help me with this

Aurora Eugene
  • 75
  • 1
  • 13
  • 1
    This is a common question here. In most of these case the email was sent by the server, but not received. Somewhere along the way it was stopped, either by your web host, or by the receiving mail server. I looked on this site for: "Unable to send Mail using PHP", and found: [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail). Please read the answers there. – KIKO Software Mar 29 '22 at 06:08
  • Here when i send code directly from CPanel it is working , but when i use code it is not. i tried everything checking port . but nothing is working @KIKOSoftware – Aurora Eugene Mar 29 '22 at 06:24
  • 1
    Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – Tangentially Perpendicular Mar 29 '22 at 08:11
  • Yeah got it Thanks – Aurora Eugene Mar 29 '22 at 09:17
  • Sorry for my late reaction. I don't know what: "... send code directly from CPanel ..." exactly means. Did you mean to write: "... send mail directly from CPanel ..."? I'm not using CPanel so I don't know what kind of mail service it has, but I'm sure there are many ways of sending emails that actually work. However, the email you send from PHP doesn't arrive, I think you should concentrate on that. – KIKO Software Mar 29 '22 at 12:00
  • 1
    Side note: I found sending emails from PHP becoming so difficult that I have resorted to using third party services. I'm using [Postmark](https://postmarkapp.com/). Another often used one is [MailChimp](https://mailchimp.com), but there are many many more. They take care of all the difficult stuff so you can concentrate on what is important. – KIKO Software Mar 29 '22 at 12:06

0 Answers0