0

I am trying to send an email through php using this:

<?php
mail("my_email", "Test Message", "welcome to the test message") or die("Error!");
?>

But when i run this in php the email doesnt come through and no error message is created and the die message does not appear anywhere.

I have got this information from http://www.php.net/manual/en/function.mail.php

What have i done wrong? I have been looking but i am unable to find out if its a problem with php or my server and everything i have followed has failed.

can someone clarify this?

----EDIT----

By the looks of it i need to do some more research in this matter, thanks for all your help and ill do some more work

4

1 回答 1

1

基本实现,但是,如果上述方法不起作用,那么我确定您需要设置MTA

HTML 代码

<form action="mail.php" method="post">
  <input type="text" name="email" />
  <input type="submit" value="submit mail" />
</form>

PHP代码:

if (isset($_POST['email']) && !empty($_POST['email'])) {
  $userEmail = $_POST['email'];
  $to = strip_tags($userEmail);
  $subject = "email subject";
  $message= 'email body message goes here';
  $headers = "From: anotheremail@test.com";

  if (mail($to,$subject,$message,$headers)) {
    echo "mail sent";
  }  else {
    echo "error sending mail";
  }
}
于 2013-03-23T16:18:59.213 回答