dongmeng0317 2014-03-05 11:01
浏览 95
已采纳

用php给自己发电子邮件

So I have a webpage with a form, and I'm trying to set up a php page where, when the submit button is clicked, it sends all the form information to my email without the user having to use Outlook or any sort of emailing software. I thought I had it right, but instead of running the PHP, it just shows a page of all the php code written out, and nothing arrives at my email. Here's the form:

<form name="infoForm" method="post" action="email.php">
<p class="form">
    Are you a registered voter in the state of Washington?<br>
    <input type="checkbox" id="yesBox"/> Yes<br><br>

    First Name: <input type="text" id="firstName"><br>
    Last Name:<input type="text" id="lastName"><br><br>

    Email: <input type="text" id="email" size="30"><br><br>
    Street Address: <input type="text" id="street1" size="30"><br>
                    <input type="text" id="street2" size="30"><br>
    City: <input type="text" id="city" size="30"><br>
    State: <input type="text" id="state" size="30"><br>
    Zip Code: <input type="text" id="zip" size="30"><br><br>
    Initials: <input type="text" id="initials" size="3"><br><br>

    <input type="submit" name="send" class="inputButton" id="send" value="Submit" disabled=true/> <input type="reset" name="resetFields" class="inputButton" value="Reset"/>
</p>
</form>

And my php code:

<?php
    if(isset($_POST['send'])){
        $to_address="tonybenwhite@live.com";
        $subject="WSA Day of Action Entry";
        $firstname=$_POST['firstname'];
        $lastname=$_POST['lastname'];
        $email=$_POST['email'];
        $street1=$_POST['street1'];
        $street2=$_POST['street2'];
        $city=$_POST['city'];
        $state=$_POST['state'];
        $zip=$_POST['zip'];
        $initials=$_POST['initials'];
        $message="Name: " .$firstname." ".$lastname."
";
        $message .="Email: " .$email."
";
        $message .="Street: " .$street1."
";
        $message .="Street: " .$street2."
";
        $message .="City: " .$city."
";
        $message .="State: " .$state."
";
        $message .="Zip Code: " .$zip."
";
        $message .="Initials: " .$initials."
";
        $headers = 'From: '.$email."
".
        'Replay-To: '.$email."
".
        'X-Mailer: PHP/' .phpversion();
        mail($to_address, $subject, $message, $headers);
        }
?><!DOCTYPE HTML>

<html>
<body>
Thank you!
</body>
</html>
  • 写回答

4条回答 默认 最新

  • dongzhuan1185 2014-03-05 11:03
    关注

    You must use this content type as text/html

    if(isset($_POST['send'])){
            $to_address="tonybenwhite@live.com";
            $subject="WSA Day of Action Entry";
            $firstname=$_POST['firstname'];
            $lastname=$_POST['lastname'];
            $email=$_POST['email'];
            $street1=$_POST['street1'];
            $street2=$_POST['street2'];
            $city=$_POST['city'];
            $state=$_POST['state'];
            $zip=$_POST['zip'];
            $initials=$_POST['initials'];
            $message="Name: " .$firstname." ".$lastname."
    ";
            $message .="Email: " .$email."
    ";
            $message .="Street: " .$street1."
    ";
            $message .="Street: " .$street2."
    ";
            $message .="City: " .$city."
    ";
            $message .="State: " .$state."
    ";
            $message .="Zip Code: " .$zip."
    ";
            $message .="Initials: " .$initials."
    ";
    
    
    $headers=" From : ". $email."
    "; 
    $headers.= 'MIME-Version: 1.0' . "
    ";
    $headers.= 'Content-type: text/html; charset=iso-8859-1' . "
    ";
    
    
            mail($to_address, $subject, $message, $headers); 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码