【问题标题】:Mail sent correctly on localhost, but not sending when uploaded to the server [duplicate]邮件在本地主机上正确发送,但在上传到服务器时未发送 [重复]
【发布时间】:2015-12-21 06:27:58
【问题描述】:

我的页面中有一个简单的邮件功能。我使用测试邮件服务器工具在本地系统上检查它,它正在发送邮件。但是当我将文件上传到服务器时,它没有发送文件

这是电子邮件代码:

if($_POST['name'])
{
    $subject = "Message from website";
    $name = $_POST['name'];
    $email = $_POST['email'];
    $number = $_POST['number'];
    $txt = " Name : " . $name . " \r\n Email : " . $email . " \r\n Contact No. : " . $number;
    $headers = 'From:' . $name . "\r\n";
    $mail=mail('xyz@gmail.com', $subject, $txt, $headers);

    if($mail)
    {

        echo "Thank You!";
    }

    if(!$mail)
    {
        echo "failed";
    }
}
else
    echo "no values entered";

我在 localhost 上看到“谢谢”消息。但是当我上传到服务器时,它显示消息“失败”。

请帮忙。

提前致谢。

【问题讨论】:

  • 您使用的是哪个服务器?
  • 其实我的学长正在上传到服务器。我不知道他使用的是哪个服务器。它在本地主机中为我工作。这是否意味着代码没问题?
  • 尝试print_r(error_get_last());而不是echo "failed";,您可以获得更多关于它如何失败的详细信息
  • 是的代码似乎还可以,服务器检查 sendmail 或 postfix 安装或未安装在服务器上的问题
  • 谢谢 bansi,Chetan Ameta,我会检查这些东西

标签: php email mail-server


【解决方案1】:

在您的编码中添加以下行。

`$this->load->library('email'); 
$config['protocol'] = 'mail'; 
$config['charset'] = 'utf-8'; 
$this->email->initialize($config); 
$this->email->set_mailtype('html');'

【讨论】:

    【解决方案2】:

    邮件功能

    $msg = "<html>
    
                                        <body>
                                        User Contact Details
                                        <table>
                                        <tr><td>Name:</td><td>".$_POST['name']."</td></tr>
    
                                        <tr><td>Mobile:</td><td>".$_POST['mobile']."</td></tr>
                                        <tr><td>Email :</td><td>".$_POST['email']."</td></tr>
                                        </table>
                                        </body>
    
                                        </html>
    
                                        ";
    
    $this->load->library('email'); 
    $config['protocol'] = 'mail'; 
    $config['charset'] = 'utf-8'; 
    $this->email->initialize($config); 
    $this->email->from('From email id'); 
    $this->email->to('$_POST['email']'); 
    $this->email->subject('Subject of ur email id'); 
    
    $this->email->message($msg); 
    $this->email->set_mailtype('html');
     if($this->email->send())
         {
    
          echo 'Thank you';
    
         }
         else
        {
             echo "failed";
        }
    

    【讨论】:

      猜你喜欢
      • 2014-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-25
      • 1970-01-01
      • 2013-01-20
      • 2019-08-03
      • 2015-03-02
      相关资源
      最近更新 更多