0

我正在创建一个联系我们的表格,它应该通过电子邮件将表格的内容发送给我。我试图在我的本地主机上发送邮件,但它没有工作,但在主机(1and1)上它工作得很好。现在,我正在新主机(Netfirms)上试用它。出于某种明显的原因,邮件函数不发送邮件,也不返回真/假值。我整晚都在谷歌上搜索解决方案或理论,但没有用。什么可能导致这种奇怪的结果?

这是邮件的PHP。

<?php
class zMail {

final public function compileMail() {
    global $tpl, $zip;

    $tpl->Define('error', null);

    # Ensure that the form was sent #
    if(isset($_POST['contact-us'])) { 

        # Make sure that the variables are set for the mailing process #
        $first_name     = $_POST['f_name'];
        $last_name      = $_POST['l_name'];
        $event_type     = $_POST['event'];
        $date           = $_POST['date'];
        $guests         = $_POST['guests'];
        $from           = $_POST['email'];
        $phone          = $_POST['phone'];

        # Place Where E-Mail should be sent to #
        $to             = $zip['Social']['Email'];

        # Are all fields completed? #
        if(!empty($first_name) && !empty($last_name) && !empty($event_type) && !empty($date) && !empty($guests) && !empty($from) && !empty($phone)) {
            switch($event_type) {
                case '1':
                    return 'Baby Shower';
                break;
                case '2':
                    return 'Wedding';
                break;
                case '3':
                    return 'Kids Party';
                break;
                case '4':
                    return 'Birthday';
                break;
                case '5':
                    return 'Other';
                break;
            }

            switch($guests) {
                case '1':
                    return '10-25 People';
                break;
                case '2':
                    return '25 - 50 People';
                break;
                case '3':
                    return '50 - 75 People';
                break;
                case '4':
                    return '75 - 100+ People';
                break;
            }

            $message = '<ul>
                            <li><b>First & Last Name: </b><span style="float: right;">' . $first_name . ' ' . $last_name . '</span></li>
                            <li><b>Event Type: </b><span style="float: right;">' . $event_type . '</span></li>
                            <li><b>Date: </b><span style="float: right;">' . $date . '</span></li>
                            <li><b>Guests: </b><span style="float: right;">' . $guests . '</span></li>
                            <li><b>Email: </b><span style="float: right;">' . $from . '</span></li>
                            <li><b>Telephone: </b><span style="float: right;">' . $phone . '</span></li>
                            <li><b>Add`l Information: </b><span style="float: right;">' . $notes . '</span></li>
                        </ul>';

            $subject = "{site: title} - New Client Inquiry";
            $headers = "From: IntactDev@gmail.com\r\n" . 
                        'X-Mailer: PHP/' . phpversion() . "\r\n" . 
                        "MIME-Version: 1.0\r\n" . 
                        "Content-Type: text/html; charset=utf-8\r\n" . 
                        "Content-Transfer-Encoding: 8bit\r\n\r\n"; 

            $retval = mail($to, $subject, $message, $headers);
            if($retval == true) {
              $tpl->Define('error', '<span class="error">Message sent successfully!</span>');
            } else {
              $tpl->Define('error', '<span class="error">Email could not be sent!</span>');
           }
        } else {
            $tpl->Define('error', '<span class="error">Please fill in all fields!</span>');
        }
    }
}
}
?>
4

2 回答 2

2

所以我很好奇这在其他主机上是如何工作的。在您使用邮件功能之前,您将退出该功能。

你的两个 switch 语句:

        switch($event_type) {
            case '1':
                return 'Baby Shower';
            break;
            case '2':
                return 'Wedding';
            break;
            case '3':
                return 'Kids Party';
            break;
            case '4':
                return 'Birthday';
            break;
            case '5':
                return 'Other';
            break;
        }

        switch($guests) {
            case '1':
                return '10-25 People';
            break;
            case '2':
                return '25 - 50 People';
            break;
            case '3':
                return '50 - 75 People';
            break;
            case '4':
                return '75 - 100+ People';
            break;
        }

这些是返回的字符串,这意味着只要匹配了一个 case,switch 语句之后的任何代码都不会被执行。

也许您正在尝试重新定义变量,如下所示:

switch($event_type) {
    case '1':
        $event_type =  'Baby Shower';
        break;
    case '2':
        $event_type =  'Wedding';
        break;
    case '3':
        $event_type =  'Kids Party';
        break;
    case '4':
        $event_type =  'Birthday';
        break;
    case '5':
        $event_type =  'Other';
        break;
}

switch($guests) {
    case '1':
        $guests =  '10-25 People';
        break;
    case '2':
        $guests =  '25 - 50 People';
        break;
    case '3':
        $guests =  '50 - 75 People';
        break;
    case '4':
        $guests =  '75 - 100+ People';
        break;
}
于 2013-07-01T20:50:39.253 回答
0

您是否检查了端口 25 是否打开?这是一个链接: http ://www.yougetsignal.com/tools/open-ports/

于 2013-07-01T19:52:24.067 回答