PHP不发送电子邮件

时间:2014-01-17 11:25:43

标签: php email

我刚接触php编码。我试图从一个html页面发送一封电子邮件。它被重定向到我的'email.php',但它没有发送电子邮件。我的代码就在这里..

<?php

//if "email" is filled out, send email

  //send email
  $name = $_REQUEST['your-name'] ;
   $email = $_REQUEST['your-email'] ;
   $company= $_REQUEST['company'] ;
    $website= $_REQUEST['website'] ;
  $message=$name."<br>".$company."<br>".$website."<br>".$email;
  $subject = 'Hai there' ;
  $message = $_REQUEST['message'] ;
  mail("sample@gmail.com", $subject,
  $message, "From:" . $email);
  if(mail()){
  echo 'successfull';
  }
  else{
   echo 'not successfull';
  }


?>

它总是显示'不成功'。

2 个答案:

答案 0 :(得分:2)

替换

if(mail()){

if(mail("sample@gmail.com", $subject,  $message, "From:" . $email)){

答案 1 :(得分:0)

你可能需要查看你的php.ini配置,看一下这个评论:

https://stackoverflow.com/a/8804035/2910910

这条评论:

http://www.php.net/manual/en/ref.mail.php#77499

祝你好运!