【问题标题】:php mail body issuephp邮件正文问题
【发布时间】:2016-06-21 09:14:35
【问题描述】:

我一直在制作公司扩展列表。唯一不起作用的是当管理员在扩展列表中的表单上添加新用户时,我希望它通过电子邮件将表单详细信息发送给我的老板,以便每次添加某人时他都知道。

我读了一点,因为我对 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">

【问题讨论】:

  • 请添加您的尝试并编辑您的问题。
  • 你的问题到底是什么?
  • @limonik 编辑先生

标签: php html


【解决方案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 标签来帮助整理电子邮件,如果您注意到在 $headers 我添加了 $headers .= "Content-type: text/html\r\n"; 如果这不是您要求的,请在此处发表评论,以便我可以编辑我的答案并祝您好运

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 2015-11-12
    相关资源
    最近更新 更多