联系表格向收件人发送3份副本

时间:2015-03-07 21:16:48

标签: php contact-form

我的网站上有一个联系表格,它会调用.php邮件处理程序来发送查询。每次发送查询时,我都会收到3份电子邮件。

任何可能导致此问题的想法?

以下脚本位于标题中:

<script type="text/javascript">
$(window).load(function(){
$('#form').TMForm({ 
ownerEmail:'admin@endlessflooring.co.nz'
})
})
</script>

联系表格如下:

<form id="form">                              
<div class="success_wrapper">
<div class="success-message">Contact form submitted</div>
</div>
<label class="name">
<input type="text" placeholder="Name" data-constraints="@Required 

@JustLetters" />
<span class="empty-message">*This field is required.</span>
<span class="error-message">*This is not a valid name.</span>
</label>

<label class="email">

<input type="text" placeholder="E-mail" data-constraints="@Required @Email" />
<span class="empty-message">*This field is required.</span>
<span class="error-message">*This is not a valid email.</span>
</label>

<label class="phone">

<input type="text" placeholder="Phone" data-constraints="@Required @JustNumbers"/>
<span class="empty-message">*This field is required.</span>
<span class="error-message">*This is not a valid phone.</span>
</label>

<label class="state">
 <input type="text" placeholder="City" data-constraints="@Required @JustLetters"/>
<span class="empty-message">*This field is required.</span>
<span class="error-message">*This is not a valid city.</span>
</label>        

<label class="message">

<textarea placeholder="Message" data-constraints='@Required @Length(min=2,max=999999)'></textarea>
<span class="empty-message">*This field is required.</span>
<span class="error-message">*The message is too short.</span>
</label>
<div>
<div class="clear"></div>
<div class="btns">

<a href="#" data-type="submit" class="link1">send message</a></div>
</div>
</form>   

邮件处理程序如下:

<?php

    //SMTP server settings  
    $host = "smtp.host.com";
    $port = "587";
    $username = "";
    $password = "";


    $messageBody = "";

    if($_POST['name']!='false'){
        $messageBody .= '<p>Name: ' . $_POST["name"] . '</p>' . "\n";
        $messageBody .= '<br>' . "\n";
    }
    if($_POST['email']!='false'){
        $messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
        $messageBody .= '<br>' . "\n";
    }else{
        $headers = '';
    }

    if($_POST['phone']!='false'){       
        $messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
        $messageBody .= '<br>' . "\n";
    }   
    if($_POST['state']!='false'){       
        $messageBody .= '<p>Suburb: ' . $_POST['state'] . '</p>' . "\n";
        $messageBody .= '<br>' . "\n";
    }
    if($_POST['message']!='false'){
        $messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
    }

    if($_POST["stripHTML"] == 'true'){
        $messageBody = strip_tags($messageBody);
    }

    if($host=="" or $username=="" or $password==""){
        $owner_email = $_POST["owner_email"];
        $headers = 'From:' . $_POST["email"] . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n";
        $subject = 'Endless Flooring Quote Request';

        try{ 
            if(!mail($owner_email, $subject, $messageBody, $headers)){
                throw new Exception('mail failed');
                }else{
                echo 'mail sent';
            }
            }catch(Exception $e){
            echo $e->getMessage() ."\n";
        }
    }else{  
        require_once 'Mail.php';

        $to = $_POST["owner_email"];
        $subject = 'Endless Flooring Quote Request' . $_POST["name"];
        $headers = array (
        'From' => 'From:' . $_POST["email"] . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n",
        'To' => $to,
        'Subject' => $subject);

        $smtp = Mail::factory(
                    'smtp',
                    array (
                        'host' => $host,
                        'port' => $port,
                        'auth' => true,
                        'username' => $username,
                        'password' => $password));

        $mail = $smtp->send($to, $headers, $messageBody);

        try{
            if(PEAR::isError($mail)){
                echo $mail->getMessage();
                }else{
                echo 'mail sent';
            }
            }catch(Exception $mail){
            echo $mail->getMessage() ."\n";
        }
    }   
?>

0 个答案:

没有答案