doumen5087 2014-11-04 19:29
浏览 39
已采纳

HTML发送预先写好的电子邮件

I have put a website up on the internet, and I want to have a function where a user can enter their email address into a form and when submitted, they will receive a pre-set email.

There are other questions, but none of them seemed to help me.

I have basic code here:

<form action="send.php" method="post">
<input type="text" name="mail">
<input type="submit" value="send">
</form>

Here is the send.php

<?php
$mail = $_POST['mail'];
?>
<html>
<a href="mailto:<?php echo $mail ?>"><button>SEND</button></a>
</html>

Please excuse the fact that you have to press send twice, I will change that.
What I want to do, is send the user (email is represented by $mail) a pre written document via email, not as an attachment, but a the composition of the email.

I am unsure as to weather i can just use a word document, or there is complex code behind it.

Since i am only familiar with basic visual elements, please could you explain what parts of the code do what, as i may want to tweak it.

Thanks!

  • 写回答

1条回答 默认 最新

  • doumou3883 2014-11-04 19:41
    关注

    As Fred said, the best way to approach this is via PHP's mail function. When send.php runs, you can include PHP code like

    mail($mail, "My Email Subject", "<html><b>Email Message</b></html>", $headers);
    

    Where your header variable will have to contain all the necessary information to tell your client's mail software that the string message contains HTML that should be parsed. An example header setup is as follows, from CSS Trick's lovely example for this problem:

    $headers = "From: " . strip_tags($_POST['req-email']) . "
    ";
    $headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "
    ";
    $headers .= "CC: susan@example.com
    ";
    $headers .= "MIME-Version: 1.0
    ";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1
    ";
    

    Noting that you can replace the strip_tags call with whatever set emails you want. Then, you can replace my <html><b>Email Message</b></html> with whatever code you want to make a nicely formatted email.

    Using PHP's mail() function also makes it so you do not need to click submit twice.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度