1

All I'm trying to do is just send an extremely basic e-mail to my host mail. The hosting service I'm currently using is https://www.ionos.com/ and I have a registered email with it. My website is already hosted and running. The code I'm trying to execute is this:

index.php

    <form class="" action="/contactform.php" method="post">
        <input type="text" name="name" value="">
        <input type="text" name="mail" value="">
        <textarea name="message"></textarea>
        <button type="submit" name="submit">Submit</button>
    </form>

contactform.php

if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $mail = $_POST['mail'];
    $message = $_POST['message'];

    $mailTo = 'info@installnewcooker.com';
    $headers = 'From '.$mail;
    $text = "You've received an e-mail from ".$name."\n\n".$message;

    mail($mailTo, $name, $text, $headers);
    header("Location: ../index.php");
}

The e-mail I'm trying to send the message is info@installnewcooker.com as is seen in the code. Sadly I'm not receiving anything and I don't have any clue as to why. The PHP code is not giving any errors.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Onyx
  • 5,186
  • 8
  • 39
  • 86
  • 2
    Most probably the `mail()` function is not allowed in your hosting. Or it requires configuration, like setting `sendmail_from` (try it, with `ini_set()`). I'd suggest you to use your SMTP or trying `sendmail`, it's fairly simple if you implement a library like PHPMailer https://github.com/PHPMailer/PHPMailer – Gabriel Dec 30 '18 at 21:02

2 Answers2

4

Quite likely, you need a registered account with authentication. But the mail() function does not allow such authentication.

You probably want to install a suitable class such as PHPMailer. Simply supply the instance with your authentication information for your mail service, and you should be good.

If it still does not work, you can use the debug mode of PHPMailer to investigate. If you find yourself in such a situation, chances are that your Web provider does not allow emails to be sent by a PHP process, probably to avoid abuse and spamming. In that case, you need to talk to the provider and have the function enabled, so that the mail() function will work, and possibly will need to add a custom header to identify the email sender to your Web provider for accounting/monitoring purposes. As an alternative, they might supply you with a user/password pair suitable for use with PHPMailer.

LSerni
  • 55,617
  • 10
  • 65
  • 107
0

Try this:

$headers = 'From: '.$mail;

mail($mailTo, $name, $text, $headers, "-f ".$mail);
jmp
  • 2,456
  • 3
  • 30
  • 47