【问题标题】:PHP Sending content of textarea through email using 'a href' tagPHP使用'a href'标签通过电子邮件发送textarea的内容
【发布时间】:2013-09-23 00:43:58
【问题描述】:

对于 HTML 代码,

<textarea name="email_content" rows="6" placeholder="Write something"></textarea>
<a href="./something.php">Send it</a>

对于 PHP 代码,

<?php
    $email="abcde@abc.com";
    $head = "From: email\r\n";
    $head .= "Content-type: text/html\r\n";
    $title= "Title Test";
    $body = "The text in the textarea";  
    $success = mail($email, $title, $body, $head);
?>

我希望将 textarea 中的文本转到 PHP 代码中的 $body 中。

另外,我想以 utf-8 格式发送电子邮件。

请帮忙!

【问题讨论】:

  • 我建议将其设为form 并将submit 按钮设置为看起来像一个链接,而不是尝试使用实际链接来提交表单数据。

标签: javascript php html email


【解决方案1】:

您不能这样做,因为您不是 POSTing 数据(如果您发送的电子邮件始终相同,则可以这样做)。不过,就像@David 所说,您可以让提交按钮看起来 像一个超链接。

这是 HTML 标记:

<form method="POST" action="./something.php">
    <textarea name="email_content" rows="6" placeholder="Write something"></textarea>
    <input type="submit" class="hyperlink" value="Send it">
</form>

这是 CSS 样式:

.hyperlink {
    background-color: transparent;
    text-decoration: underline;
    border: none;
    color: blue;
    cursor: pointer;
}

这就是它的样子:http://jsfiddle.net/VKuEF/1/

然后在something.php PHP 脚本中,获取你要做的 textarea 的值

$body = $_POST['email_content'];

然后用它来发送电子邮件。要为您的电子邮件使用 UTF-8 编码,您可以在邮件正文中添加 Content-Type: text/html; charset=UTF-8 标头。

【讨论】:

    猜你喜欢
    • 2016-04-22
    • 2016-07-16
    • 2017-12-21
    • 1970-01-01
    • 1970-01-01
    • 2021-01-08
    • 1970-01-01
    • 2015-10-21
    • 1970-01-01
    相关资源
    最近更新 更多