0

I'm trying to send and email using the php function mail(). I understood that if the function's return true it does not necessarily means the mail has been sent.

I installed the phpmail package and the libphp-phpmailer package but still nothing...

This is the code:

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Name: <input type="text" name="name"/>
    Mail: <input type="text" name="mail"/>
    <input type="submit" value="Send"/>
</form>
<?php

ini_set('display_errors', 1);
error_reporting(~0);

if (isset($_POST["mail"]) && isset($_POST["name"])) {
    $to_mail = $_POST["mail"];
    $to_name = ucfirst($_POST["name"]);
    $subject = "Sent using php";
    $message = "Hi " . $to_name . ", we're glad you could join us. Hope you like our page and that you're studing a lot! Good luck with whatever you're doing! :D";
    $from = "email@gmail.com";

    if(mail($to_mail, $subject, $message, $from)) {
        echo "E-Mail Sent to " . $to_mail;
    } else {
        echo "Could not send E-Mail";
    }
}
?>

Omer
  • 163
  • 1
  • 10
  • your "From" failed. – Funk Forty Niner Mar 27 '18 at 18:50
  • *"I installed the phpmail package and the libphp-phpmailer package but still nothing"* - That isn't phpmailer code, it's standard php `mail()`, to which I replaced the tag with. – Funk Forty Niner Mar 27 '18 at 18:51
  • All `mail()`'s return code is representative of is that it successfully dumped the message into the local server's queue. Whether or not anything happened after than will be in your server's logs. – Sammitch Mar 27 '18 at 18:53
  • @FunkFortyNiner Okay, I checked the `mail.log` and I did had a problem there, I solved it and now the log says the email has been sent but I still didn't actually got it int my mailbo – Omer Mar 27 '18 at 19:09
  • The "from" should be `From: email@example.com` as per the manual https://secure.php.net/manual/en/function.mail.php so it may have been rejected or sent to spam then deleted. – Funk Forty Niner Mar 27 '18 at 19:11

0 Answers0