user3187469
user3187469

Reputation: 1531

Submiting form to email address

I'm trying to have entered email address delivered to my inbox so that when user enters his email in form, I get an email notification about it.

This is the php:

<?php
if($_POST){
    $email = $_POST['email'];

//send email
    mail("[email protected]", "Newsletter Signup:" .$email);
}
?>

What am I doing wrong since it's not working atm ?

Upvotes: 0

Views: 311

Answers (1)

ˈvɔlə
ˈvɔlə

Reputation: 10272

What is the problem with this question

The reason why your mails won't be delivered can be really anything. Check the environments of your mailserver and your webserver.

  • Check your Email Account for spam filters
  • Maybe your internet provider is blocking the email because of unverified sender address
  • Firewalls problems
  • etc...

How to solve the problem

Since the mail() function implementation in php is returning a boolean, you can use this return value to detect an error:

<?php [...]

$email = $_POST['email'];

$success = mail("[email protected]", "Newsletter Signup:", $email);

if (!$success) {
  $error = error_get_last();
  var_export($error);
}

[...] ?>

Maybe this will help you to locate the problem.

Upvotes: 2

Related Questions