将表格发送到hostgator中的电子邮件

时间:2019-03-25 02:37:44

标签: php html forms formmail

我需要在hostgator中创建一个自定义表单,并且应该能够将表单输入发送到我的电子邮件地址。

我是html和表单的新手。

我已使用以下链接上的代码创建了基本的html文件:https://support.hostgator.com/articles/custom-form-mail 我没有收到任何电子邮件,因此我创建的表单运行良好。

我需要为此创建一个php文件吗? 我也不确定要放在value =“ http://www.example.com/redirect-path”>部分上的内容。

我正在使用Hostgator网站构建器。我一般不熟悉表格

=============== 我遵循的代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="content-type" content="text/html;charset=utf-8"> 
<title>FormMail Demo</title> 
<script type="text/javascript"> 
function hgsubmit() 
{ 
if (/\S+/.test(document.hgmailer.name.value) == false) alert ("Please provide your name."); 
else if (/^\S+@[a-z0-9_.-]+\.[a-z]{2,6}$/i.test(document.hgmailer.email.value) == false) alert ("A valid email address is required."); 
else if (/\S+/.test(document.hgmailer.comment.value) == false) alert ("Your email content is needed."); 
else { 
    document.hgmailer.submit(); 
    alert (' Thank you! \n Your email is sent.'); 
    } 
} 
</script> 
</head> 
<body> 
<form action="http://www.example.com/cgi-sys/formmail.pl" method="post" name="hgmailer"> 
<input type="hidden" name="recipient" value="myemail@mydomain.com"> 
<input type="hidden" name="subject" value="FormMail E-Mail"> 
Whatever you want to say here<br><br> 
Visitor Name: <input type="text" name="name" size="30" value=""><br> 
Visitor E-Mail: <input type="text" name="email" size="30" value=""><br> 
E-Mail Content: <textarea name="comment" cols="50" rows="5"></textarea><br><br>
<input type="button" value="E-Mail Me!" onclick="hgsubmit();"> 
<input type="hidden" name="redirect" value="http://www.example.com/redirect-path"> 
</form> 
</body> 
</html> 

1 个答案:

答案 0 :(得分:0)

假设您已经设置了服务器端脚本,就可以使用PHP,则可以使用以下代码编写一个不错的电子邮件模板,以实现您的意图

table { border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; } 
table td { font-family: sans-serif; font-size: 14px; vertical-align: top; }
.body { background-color: #f6f6f6; width: 100%; } 
.container { display: block; Margin: 0 auto !important;  max-width: 580px; padding: 10px; width: 580px; } 
.content { box-sizing: border-box; display: block; Margin: 0 auto; max-width: 580px; padding: 10px; }
.main { background: #fff; border-radius: 3px; width: 100%; } 
.wrapper { box-sizing: border-box; padding: 20px; } 
.footer { clear: both; padding-top: 10px; text-align: center; width: 100%; } 
.footer td, .footer p, .footer span, .footer a { color: #999999; font-size: 12px; text-align: center; } 
h1, h2, h3, h4 { color: #000000; font-family: sans-serif; font-weight: 400; line-height: 1.4; margin: 0; Margin-bottom: 30px; } 
p li, ul li, ol li { list-style-position: inside; margin-left: 5px; }
<!doctype html>
	<html>
	  <head>
		<meta name="viewport" content="width=device-width" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>Mail from Sender</title>
	  </head>
      <body class=""><table border="0" cellpadding="0" cellspacing="0" class="body"><tr><td>&nbsp;</td><td class="container"><div class="content">
	<table class="main">
	  <tr>
		<td class="wrapper">
		  <table border="0" cellpadding="0" cellspacing="0">
			<tr><td>
			<center><h2>MyCompany Logo</h2></center></td>
			</tr>
			<tr>
			  <td>
				<p>Hello Receiver</p>
				<p>I am writing to you concerning this bla bla bala ab;a ba</p>
				<p>With Regards,<br>Sender</p>
				  </td>
				</tr>
			  </table>
			</td>
		  </tr>
			</table>
			<div class="footer">
			  <table border="0" cellpadding="0" cellspacing="0">
				<tr>
				  <td class="content-block">
					<span class="apple-link">
				  </td>
				</tr>
				<tr>
					<td>
					<a href="' . $url . '">MyService</a>.</td>
				  <td class="content-block powered-by">
					<ul>
						<li>Marketing</li>
						<li>Recruiting</li>
						<li>Management</li>
					</ul>
				  </td>
				</tr>
			  </table>
			</div>
		  </div>
		</td>
		<td>&nbsp;</td>
	  </tr>
	</table>
  </body>
</html>

请注意,仅是使用表格正确放置我的电子邮件内容。这是因为通过电子邮件发送的html内容有时会迷失方向