dotibrb048760 2015-03-31 10:39
浏览 117

我的PHP表单需要SMTP身份验证吗?

i have created a form and it doesnt send out emails. I contacted my host and he said I need SMTP authentication. Form needs to send reservation info.

Here is my reservation.php file:

<script>
/////////////////// RESERVATION FORM //////////////////////
        $("#ajax-contact-form").submit(function(){ 
            var str = $(this).serialize();
            document.getElementById('submit').disabled=true;
            document.getElementById('submit').value='PLEASE WAIT';
            $.ajax({ 
                type: "POST",
                url: "apartments_reservation_send.php",
                data: str,
                success: function(msg){ 
                    $("#note").ajaxComplete(function(event, request, settings){ 
                        if(msg == 'OK') 
                        { 
                            result = '<div class="notification_ok">Thank you!<br />Your request is successfully sent!</div>';
                            $("#fields").hide();
                        }
                        else 
                        { 
                            document.getElementById('submit').disabled=false;
                            document.getElementById('submit').value='Send request';
                            result = msg;
                            autoReinitialise: true;
                        } 
                        $(this).html(result);
                    });
                }
            });
            return false;
        });
</script>

<form id="ajax-contact-form" action="javascript:alert('success!');"> 
                            <table width="100%" cellpadding="3" cellspacing="3">
                                <tr>
                                    <td width="50%" align="right" style="text-align: right;">
                                        Arrival Date<span class="REQ">*</span> &rarr; <input id="arrivalDate" name="arrivalDate" size="30" type="text" class="date-pick" /> 
                                    </td>
                                    <td width="50%" align="left" style="text-align: left;">
                                        <input id="departureDate" name="departureDate" size="30" type="text" class="date-pick" />
                                        &larr; <span class="REQ">*</span>Departure Date
                                    </td>
                                </tr>
                                <tr>
                                    <td width="50%" align="right" style="text-align: right;">
                                        Adults<span class="REQ">*</span> &rarr; 
                                        <select id="Adults" name="Adults"> 
                                            <option value=""></option>
                                            <option value="0">0</option>
                                            <option value="1">1</option> 
                                            <option value="2">2</option> 
                                            <option value="3">3</option> 
                                            <option value="4">4</option> 
                                        </select>
                                    </td>
                                    <td width="50%" align="left" style="text-align: left;">
                                        <select id="Children" name="Children"> 
                                            <option value=""></option>
                                            <option value="0">0</option>
                                            <option value="1">1</option> 
                                            <option value="2">2</option> 
                                            <option value="3">3</option> 
                                            <option value="4">4</option> 
                                        </select>
                                        &larr; <span class="REQ">*</span>Children
                                    </td>
                                </tr>
                            </table>
                            <table width="100%" cellpadding="3" cellspacing="3">
                                <tr>
                                    <td width="25%" align="right" valign="middle" style="text-align: right;">Name<span class="REQ">*</span> :</td>
                                    <td width="75%" align="left" style="text-align: left;">
                                        <input type="text" id="name" name="name" value="" size="86" /> 
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" valign="middle" style="text-align: right;">E-mail<span class="REQ">*</span> :</td>
                                    <td align="left" style="text-align: left;">
                                        <input type="text" id="email" name="email" value="" size="86" /> 
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" valign="middle" style="text-align: right;">Phone<span class="REQ">*</span> :</td>
                                    <td align="left" style="text-align: left;">
                                        <input type="text" id="phone" name="phone" value="" size="86" /> 
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" style="text-align: right;">Message :</td>
                                    <td align="left" valign="top" style="text-align: left;">
                                        <textarea id="message" name="message" rows="5" cols="87"></textarea> 
                                    </td>
                                </tr>
                                <tr>
                                    <td width="100%" align="center" style="text-align: center;" colspan="2">
                                        <input class="button" type="submit" name="submit" id="submit" value="Send request" />
                                    </td>
                                </tr>
                            </table>
                        </form>

and here is my reservarion_send.php:

<?php 

$TO_EMAIL   = "info@thebunchofgrapesinn.com";
$FROM_EMAIL = "info@thebunchofgrapesinn.com";
$FROM_NAME  = "thebunchofgrapes.com";
$SUBJECT    = "The Bunch Og Grapes - Apartment Reservation";
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;

if($post)
{
    include 'functions.php';

    $ARIVAL_DATE        = trim($_POST['arrivalDate']); 
    $DEPARTURE_DATE     = trim($_POST['departureDate']); 
    $ADULTS             = trim($_POST['Adults']); 
    $CHILDREN           = trim($_POST['Children']); 
    $EMAIL              = trim($_POST['email']);
    $PHONE              = trim($_POST['phone']); 
    $NAME               = stripslashes($_POST['name']);
    $MESSAGE            = stripslashes($_POST['message']);

    $ERROR = '';
    if(!$ARIVAL_DATE) 
    {
        $ERROR .= 'Please enter Arrival Date<br />';
    }
    if(!$DEPARTURE_DATE) 
    {
        $ERROR .= 'Please enter Departure Date<br />';
    }
    //if(!$ADULTS) 
    //{
        //$ERROR .= 'Please pick number of Adults<br />';
    //}
    //if(!$CHILDREN) 
    //{
        //$ERROR .= 'Please pick number of Children<br />';
    //}
    if(!$NAME) 
    {
        $ERROR .= 'Please enter Your Name.<br />';
    }
    if(!$EMAIL) 
    {
        $ERROR .= 'Please enter Email address.<br />';
    }
    if($EMAIL && !ValidateEmail($EMAIL)) 
    {
        $ERROR .= 'Please enter valid Email address.<br />';
    }
    if(!$PHONE) 
    {
        $ERROR .= 'Please enter You Phone Number.<br />';
    }
    //if(!$MESSAGE || strlen($MESSAGE) < 15) {
        //$ERROR .= "Molimo unesite poruku. <br />Poruka mora imati najmanje 15 karaktera.<br />";
    //}
    
    $FULL_MESSAGE = "ARIVAL DATE = $ARIVAL_DATE
DEPARTURE DATE = $DEPARTURE_DATE
ADULTS = $ADULTS
CHILDREN = $CHILDREN
NAME = $NAME
EMAIL = $EMAIL
PHONE = $PHONE
MESSAGE = $MESSAGE";
    
    if(!$ERROR)
    {
        $mail = mail($TO_EMAIL, $SUBJECT, $FULL_MESSAGE,
             "From: ".$FROM_NAME." <".$FROM_EMAIL.">
"
            ."Reply-To: ".$FROM_EMAIL."
"
            ."X-Mailer: PHP/" . phpversion());

        if($mail) {
            echo 'OK';
        }
    }
    else {
        echo '<div class="notification_error">'.$ERROR.'</div>';
    }

}
?>

and here is the link of the webpage http://thebunchofgrapesinn.com/apartments_reservation

I am not sure how to add SMTP authentication and what is wrong here, can someone help?

</div>
  • 写回答

3条回答 默认 最新

  • dqwh0108 2015-03-31 10:58
    关注

    The behavior of php's mail() function varies depending on the server OS. Windows doesn't have a built in non-SMTP option like Unix-based servers. mail() is also limited in general without some advanced knowledge of working with headers.

    If it's not inappropriate here to recommend a tool for the job, PHPMailer is a convenient enough goto solution for sending email from php. If your server is Unix/Linux based, you can leave out $mail->isSMTP() and the related options and PHPMailer will use the server's sendmail implementation. If you are on Windows or have SMTP details handy, PHPMailer makes that simple enough.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图