首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >以下发件人地址失败: myname@gmail.com

以下发件人地址失败: myname@gmail.com
EN

Stack Overflow用户
提问于 2012-12-04 14:15:21
回答 2查看 7.8K关注 0票数 4

我正在尝试在Joomla 2.5中建立一个联系人表单。在填写完所有字段并提交表单后,我收到如下错误:

以下发件人地址失败: myname@gmail.com。

我使用的电子邮件是有效的。

我的SMTP设置如下:

邮件设置

Mailer: SMTP Server
Mail from: myname@gmail.com
From Name: joomla 
Sendmail Path: /usr/sbin/sendmail
SMTP Authentication: Yes
SMTP Security: SSL 
SMTP Port: 465 
SMTP Username: myname@gmail.com
SMTP Password: ****** 
SMTP Host: smtp.gmail.com

这是发送电子邮件的代码

<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_mailto
 * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

    defined('_JEXEC') or die;

/**
 * @package     Joomla.Site
 * @subpackage  com_mailto
 */

    class MailtoController extends JControllerLegacy
    {
    /**
     * Show the form so that the user can send the link to someone
     *
     * @access public
     * @since 1.5*/

    function mailto()

     {
         $session = JFactory::getSession();
     $session->set('com_mailto.formtime', time());
     JRequest::setVar('view', 'mailto');
     $this->display();
     }

    /**
     * Send the message and display a notice
     *
     * @access public
     * @since 1.5
     */
    function send()
    {
        // Check for request forgeries
        JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));

        $app    = JFactory::getApplication();
        $session = JFactory::getSession();
        $db = JFactory::getDbo();

        $timeout = $session->get('com_mailto.formtime', 0);
        if ($timeout == 0 || time() - $timeout < 20) {
            JError::raiseNotice(500, JText:: _ ('COM_MAILTO_EMAIL_NOT_SENT'));
            return $this->mailto();
        }

        $SiteName   = $app->getCfg('sitename');
        $MailFrom   = $app->getCfg('mailfrom');
        $FromName   = $app->getCfg('fromname');

        $link       = MailtoHelper::validateHash(JRequest::getCMD('link', '', 'post'));

        // Verify that this is a local link
        if (!$link || !JURI::isInternal($link)) {
            //Non-local url...
            JError::raiseNotice(500, JText:: _ ('COM_MAILTO_EMAIL_NOT_SENT'));
            return $this->mailto();
        }

        // An array of email headers we do not want to allow as input
        $headers = array (  'Content-Type:',
                            'MIME-Version:',
                            'Content-Transfer-Encoding:',
                            'bcc:',
                            'cc:');

        // An array of the input fields to scan for injected headers
        $fields = array(
            'mailto',
            'sender',
            'from',
            'subject',
        );

        /*
         * Here is the meat and potatoes of the header injection test.  We
         * iterate over the array of form input and check for header strings.
         * If we find one, send an unauthorized header and die.
         */
        foreach ($fields as $field)
        {
            foreach ($headers as $header)
            {
                if (strpos($_POST[$field], $header) !== false)
                {
                    JError::raiseError(403, '');
                }
            }
        }

        /*
         * Free up memory
         */
        unset ($headers, $fields);

        $email              = JRequest::getString('mailto', '', 'post');
        $sender             = JRequest::getString('sender', '', 'post');
        $from               = JRequest::getString('from', '', 'post');
        $subject_default    = JText::sprintf('COM_MAILTO_SENT_BY', $sender);
        $subject            = JRequest::getString('subject', $subject_default, 'post');

        // Check for a valid to address
        $error  = false;
        if (! $email  || ! JMailHelper::isEmailAddress($email))
        {
            $error  = JText::sprintf('COM_MAILTO_EMAIL_INVALID', $email);
            JError::raiseWarning(0, $error);
        }

        // Check for a valid from address
        if (! $from || ! JMailHelper::isEmailAddress($from))
        {
            $error  = JText::sprintf('COM_MAILTO_EMAIL_INVALID', $from);
            JError::raiseWarning(0, $error);
        }

        if ($error)
        {
            return $this->mailto();
        }

        // Build the message to send
        $msg    = JText :: _('COM_MAILTO_EMAIL_MSG');
        $body   = sprintf($msg, $SiteName, $sender, $from, $link);

        // Clean the email data
        $subject = JMailHelper::cleanSubject($subject);
        $body    = JMailHelper::cleanBody($body);
        $sender  = JMailHelper::cleanAddress($sender);

        // Send the email
        if (JFactory::getMailer()->sendMail($from, $sender, $email, $subject, $body) !== true)
        {
            JError::raiseNotice(500, JText:: _ ('COM_MAILTO_EMAIL_NOT_SENT'));
            return $this->mailto();
        }

        JRequest::setVar('view', 'sent');
        $this->display();
    }
}
EN

回答 2

Stack Overflow用户

发布于 2013-01-07 22:08:37

只需在管理页面的全局配置中更改邮件程序即可进行检查

票数 0
EN

Stack Overflow用户

发布于 2013-07-01 09:43:14

在Linux (SELINUX)上应用:

setsebool -P httpd_can_network_connect=1

setsebool -P httpd_can_sendmail=1

重新启动

在Windows上:

在php.ini中

取消评论

;extension=php_openssl.dll

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13697139

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档