php邮件正文问题

时间:2016-06-21 09:14:35

标签: php html

我一直致力于公司扩展名单。唯一不起作用的是当管理员在扩展名单中的表单上添加新用户时,我希望它将表单详细信息通过电子邮件发送给我的老板,这样每次有人加入时他就会知道。

我读了一下,因为我对php很新,但是我找到了这个mailto html命令,它很好地将主题行放入正确的电子邮件地址,但是正文看起来很糟糕。这一切都像这样混淆了:

name:jurgen&extension number:242&email:aksda@skdna.com&mode=added

我已经阅读了关于电子邮件的PHP脚本,但我对如何做到这一点很困惑。有人能告诉我一个完成这个的方法吗?我想要第一个按钮发送电子邮件,然后必须显示第二个按钮才能将数据添加到数据库中。

我目前的代码:

<form name="form1" action="<?=$_SERVER['PHP_SELF'];?>?mode=added" method="post">
<div align="center"><table class="searchable">
<tr><td>Extension:</td><td><div align="center">
<input type="text" name="ext" required />
<span class="error">* <?php echo $nameErr;?></span>
</div></td></tr>
<tr><td>Name:</td><td><div align="center">
<input type="text" name="name" required />
<span class="error">* <?php echo $nameErr;?></span>
</div></td></tr>
 <tr><td>Department:</td><td><div align="center"><select name="department" required>
            <option value="VW NEW CARS ADMIN AND STOCK CONTROL">Value 4</option>
            <option value="value 5">value 5</option>
            <option value="value 6">value 6</option>
            <option value="value 3">value 3</option>
            <option value="value 4">value 4</option>
    </select>
<span class="error">* <?php echo $nameErr;?></span>
</div></td></tr>
<tr><td>Email:</td><td><div align="center">
<input type="text" name="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" name="email" title="Example: user@company.co.za" required/>
<span class="error">* <?php echo $nameErr;?></span>
</div></td></tr>
<tr><td>Cellphone:</td><td><div align="center">
<input type="text" name="phone" />
</div></td></tr>
<tr><td colspan="2" align="center">| <button type="submit" formaction="mailto:email@address.com?subject=New User Added To Extension List" enctype="text/plain" method="get">Email Boss</button>
<tr><td colspan="2" align="center"><a href="javascript:history.go(-1);">Back</a> | <input type="submit" name="submit" id="submit"  value="Add New Contact"<?php if($disable ==1){?>disabled<?php } ?>/></td></tr>
<input type="hidden" name="mode" value="added">

1 个答案:

答案 0 :(得分:1)

如果您想在电子邮件中使用html建立良好的身体设计, 例如:

                                    $to = $email;
                                $message = "
                                <table width='100%' border='0' cellspacing='0' cellpadding='3'>
                                   <tr>
                                    <td colspan=2><b>SignalShare</b></td>
                                  </tr>
                                   <tr>
                                    <td colspan=2>Thank you for creating an account.</td>
                                  </tr>
                                    </table>
                                    <hr><h3>Account info</h3><hr>
                                    <table width='100%' border='0' cellspacing='0' cellpadding='3'>
                                  <tr>
                                    <td width='28%' >Username : </td>
                                    <td width='72%'>".$username."</td>
                                  </tr>
                                  <tr>
                                    <td>Email : </td>
                                    <td>".$email."</td>
                                  </tr>
                                </table>
                                <p>SignalChat advise you not to delete this email for it contains informations that could be in use later.</p>
                                    <hr><h3>Account activation</h3><hr>
                                    <p>If you wish to activate your account please use the following link : </p>
                                    <p><a href = 'localhost/SignalShare/activate.php?code=$code&user=$username' style = 'text-decoration: none; color: blue;' >Activate account</a></p>
                                    <hr>
                                    <p>If this email does not concern you please ignore it.</p>
                                    <p>All regards.</p>
                                    <p>SignalShare.</p>
                                    ";
                                $subject = "Accout activation";                                 
                                $headers  = "From: SignaShare\r\n";
                                $headers .= "Content-type: text/html\r\n"; 

                                mail($to, $subject, $message, $headers);        
                                header("Location: success.php?email=".$email."");

正如您所看到的,我正在使用表格和html标签来帮助整理电子邮件,如果您在$ header中注意到我添加了$ headers。=&#34; Content-type:text / html \ r \ n&n& #34 ;;
如果这不是你要求的,请在这里评论,这样我就可以编辑我的答案并祝你好运