网站上的联系表格来自匿名@

时间:2014-02-27 15:34:23

标签: php forms contact

我有一个工作精细的联系表格,唯一的问题是发件人是一个电子邮件地址,如anonymus@name-hosting.com,我希望它是类似于电子邮件地址的网站..我希望我很清楚...这是我的代码:

    <?php

// Site Info
$site_name  = 'Azienda Agricola';
$site_email = 'mail@my-site.it'; 

if(isset($_POST['reservation_email'])){
    $reservation_name         = $_POST['reservation_name'];
    $reservation_address      = $_POST['reservation_address'];
    $reservation_email        = $_POST['reservation_email'];
    $reservation_adults       = $_POST['reservation_adults'];
    $reservation_children     = $_POST['reservation_children'];
    $reservation_arrival      = $_POST['reservation_arrival'];
    $reservation_departure    = $_POST['reservation_departure'];
    $reservation_phone        = $_POST['reservation_phone'];
    $reservation_requirements = $_POST['reservation_requirements'];
    $contact_email = $reservation_email;
    $from_email =  $reservation_email;

    $reservation_name         = "Nome: $reservation_name <br />";
    $reservation_address      = "Indirizzo: $reservation_address <br />";
    $reservation_email        = "Email:  $reservation_email <br />";
    $reservation_adults       = "Adulti: $reservation_adults <br />";
    $reservation_children     = "Bambini: $reservation_children <br />";
    $reservation_arrival      = "Data arrivo: $reservation_arrival <br />";
    $reservation_departure    = "Data partenza: $reservation_departure <br />";
    $reservation_phone        = "Numero telefono: $reservation_phone <br />";
    $reservation_requirements = "Richieste speciali: <br /> $reservation_requirements <br />";

    $to = $site_email;
    $subject = "Request from ".$site_name;
    $header  = 'MIME-Version: 1.0' . "\r\n";
    $header .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    $header .= 'From:'.$reservation_email. " \r\n";
    $message = "
        Hai ricevuto una nuova richiesta di prenotazione! <br />
        $reservation_name
        $reservation_address
        $reservation_email
        $reservation_adults
        $reservation_children
        $reservation_arrival
        $reservation_departure
        $reservation_phone
        $reservation_requirements
    ";

    // Send Mail
    if(@mail($to,$subject,$message,$header)) {
        $send = true;
    } else {
        $send = false;
    }

    if(isset($_POST['ajax'])){
        if($send)
            echo 'success';
        else
            echo 'error';
    }
}

我希望有人可以帮助我, 先感谢您。 F。

2 个答案:

答案 0 :(得分:0)

尝试在您的电子邮件功能中添加第5个参数,例如:"-f $reservation_email"

类似于:

mail($to,$subject,$message,$header, "-f $reservation_email");

答案 1 :(得分:0)

使用mail()函数时,邮件由服务器中预先配置的电子邮件地址发送。如果您需要通过特定的电子邮件地址发送,可能您应该使用SMTP身份验证,例如使用PHPMailer。尝试使用参数“From”在标题中“说”另一个地址可能会增加邮件被归类为垃圾邮件的可能性。 试一试:http://phpmailer.worxware.com/index.php?pg=examplebsmtp