0
<?php

    $to = "dominicsham2000@gmail.com";

    $subject = "PHP Book Ch16";
    $encoded_subject = "=?utf-8?B?".base64_encode($subject)."?=";

    $message = "From a testing mail\n\nIf you received, the program runs successfully!";

    if (mail($to, $encoded_subject, $message)) {
        echo "Email successfully sent to $to_email...";
    } else {
        echo "Email sending failed...";
    }
?>

Here is my PHP script in order to send a message to myself. The configuration of the SMTP port has no problems however it only states the failure in sending email. May I ask where is the issue and how to solve in order to successfully send to the corresponding recipient?

  • Do you have SMTP set up on server and in PHP configuration? Usually PHP native `mail` function is not used as it has poor error reporting functionality. I would use https://github.com/PHPMailer/PHPMailer or https://swiftmailer.symfony.com/docs/introduction.html – user3783243 Aug 10 '21 at 10:21
  • Any ways or guidelines to set up SMTP on my server? – Dominic Ching Hei Aug 10 '21 at 10:22
  • Not sure what your server is so can't advise there – user3783243 Aug 10 '21 at 10:24

0 Answers0