通过我的网页发送电子邮件? [英] Send an Email through my webpage?

查看:105
本文介绍了通过我的网页发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我创建了一个名为index1.html的html文件,其中包含多个文本框以收集用户信息



 <  表格   名称  =  index1   方法  =  post    action   =  sendeail.php >  

< width = 450px >

< tr >

< td valign = top >

< label for = first_name > 首先姓名* < / label >

< / td >

< td valign = top < span class =code-keyword>>

< 输入 type = text name = first_name maxlength = 50 size = 30 >

< / td >

< / tr >

< tr >

< td valign = top >

< label = last_name > 姓氏* < < span class =code-leadattribute> / label >

< ; / td >

< td valign = top >

< input type = text name = last_name maxlength = 50 size = 30 < span class =code-keyword>>

< / td >

< / tr >

< tr >

< td valign = top >

< label for = email > ; 电子邮件地址* < / label >

< / td >

< td valign = top >

< 输入 type = text 名称 = email maxlength = 80 size = 30 >

< / td >

< / tr >

< tr >

< span class =code-keyword>< td valign = top >

< label = 电话 > 电话号码< / label >

< / td >

< < /跨度> td valign = top >

< span class =code-keyword>< input type = text 名称 = 电话 maxlength = 30 size = 30 >

< / td < span class =code-keyword>>

< / tr >

< tr >

< td valign = top >

< label for = comments > 评论* < / label >

< / td >

< td valign = top >

< textarea 名称 = 评论 maxlength = 1000 cols = 25 = < span class =code-keyword> 6 > < / textarea >

< / td >

< / tr >

< span class =code-keyword>< tr >

< td < span class =code-attribute> colsp = 2 样式 = text-align:center >

< 输入 type = 提交 value = 提交 > < a href = http://www.freecontactform.com/email_form.php > 电子邮件表单< / a >

< / td >

< / tr >

< / table >

< / form >

< br $> b $ b



之后我创建了一个包含函数的php文件





 <?php  

if(isset($ _ POST [' email'])){



// 编辑2根据需要使用

$ email_to = ruvee@jspark.co;

$ email_subject = 您的电子邮件主题行;





函数死亡($ error){

/ / 您的错误代码可以在这里

echo 我们非常抱歉,但您提交的表单中发现了错误。;

echo 这些错误出现在下面。< br />< br />;

echo $ error。 < br />< br />;

echo 请转到返回并修复这些错误。< br />< br />;

die();

}



// 验证预期数据存在

if(!isset($ _ POST [' first_name'])||

!isset($ _ POST [' last_name '])||

!isset($ _ POST [' email' ])||

!isset($ _ POST [' telephone'])||

!isset($ _ POST [' comments'])){

死亡(' 我们很抱歉,但似乎有您提交的表单存在问题。');

}



$ first_name = $ _POST [' first_name']; // required

$ last_name = $ _POST [' last_name']; // required

$ email_from = $ _POST [' email']; // required

$电话 = $ _POST [' telephone']; // 不需要

$ comments = $ _POST [' comments']; // required



$ error_message = ;

$ email_exp = ' /^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

if(!preg_match($ email_exp,$ email_from)){

$ error_message 。= ' 您输入的电子邮件地址似乎无效。< br />';

}

$ string_exp = < span class =code-string> / ^ [A-Za-z .'-] + $ /;

if(!preg_match($ string_exp,$ first_name)){

$ error_message 。= ' 您输入的名字似乎无效。< br />';

}

if(!preg_match($ string_exp,$ last_name)){

$ error_message 。= ' 您输入的姓氏似乎无效。< br />' ;

}

if(strlen($ comments)< 2){

$ error_message 。= ' 您输入的评论似乎无效。< br />';

}

if(strlen($ error_message)> 0){

death($ error_message);

}

$ email_message = < span class =code-string>下面的表单详细信息。\ nn \ n
;



函数clean_string($ string){

$ bad = array( content-type < span class =code-string> bcc:
to: cc: HREF);

return str_replace($ bad, ,$字符串);

}



$ email_message 。= 名字: .clean_string($ first_name)。 \\\
;

$ email_message 。= 姓氏: .clean_string($ last_name)。 \ n;

$ email_message 。= 电子邮件: .clean_string($ email_from)。 \ n;

$ email_message 。= 电话: .clean_string($ telephone)。 \ n;

$ email_message 。= 评论: .clean_string($ comments)。 \ n;





// 创建电子邮件标题

$ headers = ' From:'。$ email_from。 \\\\ n

' 回复:'。$ email_from。 \\\\ n

' X-Mailer:PHP /'。 phpversion();

@mail($ email_to,$ email_subject,$ email_message,$ headers);

?>



<! - 在此处包含您自己的成功HTML - >



感谢您与我们联系。我们会尽快与您联系。



<? php

}

?>





我上传到主机(服务器)之前。我通过dreamviewer中的localview(桌面运行)测试了它。

我已经正确输入了所有数据。



我检查了我的没有收到邮箱,当我点击我的提交按钮时,它将预览我的sendeail.php文件以及

解决方案

_POST [' email'])){



// 根据需要编辑2条线


email_to = ruvee@jspark.co;


email_subject = 您的电子邮件主题行;





函数死亡(


First i created a html file called index1.html which consists serveral textboxs to gather user information

<form name="index1" method="post" action="sendeail.php">

<table width="450px">

<tr>

 <td valign="top">

  <label for="first_name">First Name *</label>

 </td>

 <td valign="top">

  <input  type="text" name="first_name" maxlength="50" size="30">

 </td>

</tr>

<tr>

 <td valign="top"">

  <label for="last_name">Last Name *</label>

 </td>

 <td valign="top">

  <input  type="text" name="last_name" maxlength="50" size="30">

 </td>

</tr>

<tr>

 <td valign="top">

  <label for="email">Email Address *</label>

 </td>

 <td valign="top">

  <input  type="text" name="email" maxlength="80" size="30">

 </td>

</tr>

<tr>

 <td valign="top">

  <label for="telephone">Telephone Number</label>

 </td>

 <td valign="top">

  <input  type="text" name="telephone" maxlength="30" size="30">

 </td>

</tr>

<tr>

 <td valign="top">

  <label for="comments">Comments *</label>

 </td>

 <td valign="top">

  <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>

 </td>

</tr>

<tr>

 <td colspan="2" style="text-align:center">

  <input type="submit" value="Submit">   <a href="http://www.freecontactform.com/email_form.php">Email Form</a>

 </td>

</tr>

</table>

</form>




After that i created a php file which consists functions


<?php
 
if(isset($_POST['email'])) {
 
     
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "ruvee@jspark.co";
 
    $email_subject = "Your email subject line";
 
     
 
     
 
    function died($error) {
 
        // your error code can go here
 
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo "These errors appear below.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Please go back and fix these errors.<br /><br />";
 
        die();
 
    }
 
     
 
    // validation expected data exists
 
    if(!isset($_POST['first_name']) ||
 
        !isset($_POST['last_name']) ||
 
        !isset($_POST['email']) ||
 
        !isset($_POST['telephone']) ||
 
        !isset($_POST['comments'])) {
 
        died('We are sorry, but there appears to be a problem with the form you submitted.');      
 
    }
 
     
 
    $first_name = $_POST['first_name']; // required
 
    $last_name = $_POST['last_name']; // required
 
    $email_from = $_POST['email']; // required
 
    $telephone = $_POST['telephone']; // not required
 
    $comments = $_POST['comments']; // required
 
     
 
    $error_message = "";
 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
 
  }
 
    $string_exp = "/^[A-Za-z .'-]+$/";
 
  if(!preg_match($string_exp,$first_name)) {
 
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
 
  }
 
  if(!preg_match($string_exp,$last_name)) {
 
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
 
  }
 
  if(strlen($comments) < 2) {
 
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 
  }
 
  if(strlen($error_message) > 0) {
 
    died($error_message);
 
  }
 
    $email_message = "Form details below.\n\n";
 
     
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
 
     
 
    $email_message .= "First Name: ".clean_string($first_name)."\n";
 
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
 
    $email_message .= "Email: ".clean_string($email_from)."\n";
 
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
 
    $email_message .= "Comments: ".clean_string($comments)."\n";
 
     
 
     
 
// create email headers
 
$headers = 'From: '.$email_from."\r\n".
 
'Reply-To: '.$email_from."\r\n" .
 
'X-Mailer: PHP/' . phpversion();
 
@mail($email_to, $email_subject, $email_message, $headers); 
 
?>
 
 
 
<!-- include your own success html here -->
 
 
 
Thank you for contacting us. We will be in touch with you very soon.
 
 
 
<?php
 
}
 
?>



before i uploaded it to host(server). i tested it through the localview(desktop run) in dreamviewer.
and i have input all the data correctly.

and i checked my mail box and nothing received and when i click my submit button it will preview my sendeail.php file as well

解决方案

_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED


email_to = "ruvee@jspark.co";


email_subject = "Your email subject line"; function died(


这篇关于通过我的网页发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆