doudouchan5830 2014-03-18 19:39
浏览 85

Joomla 3.0中的php邮件功能无法正常工作

I am trying to use the PHP mail function to allow an email to be sent to a user containing their password once they have entered their email address. I realise the security isn't great as I am passing the password via email but I can focus on that later. For now, I just need the functionality. It seems like the code is working as I get my success message returned, but I receive no email, any ideas? I am using Joomla 3.0 which is hosted on an Apache Server as part of the XAMPP server solution package. I also changed the settings in the global configuration to SMTP as i saw this on other forums but no luck :( I was wondering would the 'localhost' factor be causing a problem?

My code for the form action (after the user has entered their email) is;

<?php

if (isset($_POST['submit']))
  {

   mysql_connect('localhost','root','') or die("Could not connect to database");
   mysql_select_db('joomla_lifestyle') or die("Could not select database");

   $email = $_POST['email'];

   $sql = mysql_query("SELECT * FROM users WHERE Email ='$email'");
   $result = mysql_num_rows($sql);

   if ($result == 1)
   {
       $rows = mysql_fetch_array($sql);
       $password = $rows['Password'];
       $email = $rows['Email'];
    $subject = "Password Request";
    $header = "from: ciaraodonovan000@gmail.com";
    $body = "Your Password is " . $password;

    mail($email, $subject, $header, $body);
    $msg = "An Email Containing the Password has been Sent to you!";
    header("Location:/Joomla-Lifestyle/index.php?option=com_content&view=article&id=9&msg=$msg");
} else
{
   $msg = "User doesn't exist, please try again.";
   header("Location:/Joomla-Lifestyle/index.php?option=com_content&view=article&id=9&msg=$msg");    
}

    }   
    ?>
  • 写回答

1条回答 默认 最新

  • douao8204 2014-03-19 16:36
    关注

    I think your combining two separate concepts required for this to work. The first being a server to send the email and its configuration and the second being the Joomla back-end settings to utilize the server to send the email.

    Using PHP Mail won't work unless the server running PHP (XAMP in this case) has a valid means to achieve SMTP transport. I always configure Joomla to use SMTP authentication to reach out to the clients mail server and send emails.

    For your local development environment, use or set up a Gmail account and use the following settings to be able to send emails within the Joomla framework.

    mailer: SMTP

    From email: enter what you like

    From Name: enter what you like

    Sendmail Path: leave blank

    SMTP Authentication: Yes

    SMTP Security: TLS

    SMTP Port: 587

    SMTP Username: your gmail email address

    SMTP Password: your gmail email password

    SMTP Host: smtp.gmail.com

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料