dongqiao3833 2013-06-21 05:27
浏览 37
已采纳

PHP脚本无法正确发送电子邮件[关闭]

Below is my scripting for my submit form. I'm getting the email, but all it contains is the IP address and time stamp. I am not receiving any of the other information listed. I'm very new to PHP, so any help would be greatly appreciated. Also, in the email, it is saying from d91b8401, d91b8401@p3nlhg1159.shr.prod.phx3.secureserver.net. Is there a way to correct that?

<?php
include('database/config.php');
include('database/database.php');

$err = '';

if(isset($_POST['submit'])){        

    $first = addslashes(trim($_POST['first'])); 

    $last = addslashes(trim($_POST['last']));   

    $glvar = addslashes(trim($_POST['glvar']));

    $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; 
    //echo $ip;

     if(($first!='')&& ($last!='')&& ($glvar!='')){ 

        $database = new Database(HOST, DATEBASE, USERNAME, PASSWORD);   

        $allUsers = $database->select('user','glvar_id','*',"glvar_id = '".$glvar."'");
        //echo $ip;     

        $checkglvar = 0;            
    $checkglvar = count($allUsers); 

        $userData = array(              
            'first_name' => $first, 
            'last_name' => $last,               
            'glvar_id' => $glvar,       
            'ip' => $ip,        

        );      

        if(!$checkglvar) {          

            $database->insert('user',$userData);

            $message = "First Name: $first";
            $message = "Last Name: $last";
            $message = "GLVAR ID: $glvar";
            $message = "IP: $ip" . PHP_EOL;
            $message .= "TIME: " . date('Y-m-d H:i:s');

            mail("info@lvrealestateagentssignthepetition.com", "New Petition Signer", $message);

            header('location:thank-you.html');      

        }    else  $err.='<p style="color:red">Ooops! You have already signed the petition</p>';        

    } else {    

        if($first=='') $err.='<p style="color:red">Your First Name is empty</p>';   

        if($last=='') $err.='<p style="color:red">Your Last Name is empty</p>'; 

        if($glvar=='') $err.='<p style="color:red">Your GLVAR ID is empty</p>'; 

    }

}

?>
  • 写回答

3条回答 默认 最新

  • dongwei5794 2013-06-21 05:29
    关注

    You need to use .= to append to the message, you're just replacing it with each assignment.

            $message = "First Name: $first";
            $message .= "Last Name: $last";
            $message .= "GLVAR ID: $glvar";
            $message .= "IP: $ip" . PHP_EOL;
            $message .= "TIME: " . date('Y-m-d H:i:s');
    

    You can change the From: address with:

    mail("info@lvrealestateagentssignthepetition.com", "New Petition Signer", $message, "From: yourname@yourdomain.com");
    

    The fourth argument is optional headers, which override the default headers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化