Home > Backend Development > PHP Tutorial > How to submit form and send email in php_PHP tutorial

How to submit form and send email in php_PHP tutorial

WBOY
Release: 2016-07-13 10:01:24
Original
837 people have browsed it

How to send emails by submitting forms in php

This article mainly introduces the method of sending emails by submitting forms in php. It analyzes the techniques of sending emails by operating forms in php, which is very practical. Value, friends in need can refer to it

The example in this article describes how to submit a form to send an email in PHP. Share it with everyone for your reference. The details are as follows:

Save the following html code to: email.html file

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

Simple Send Mail

Mail Form

To

Subject
Message

1 2

3

4

5

6

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

if (empty ($_POST['mailto']) ) {

die ( "Recipient is blank! ") ;

}

if (empty ($_POST['$mailsubject']) ){

$mailsubject=" " ;

}

if (empty ($_POST['$mailbody']) ) {

$mailbody=" " ;

}

$result = mail ($mailto, $mailsubject, $mailbody) ;

//send the email

if ($result) {

echo "Email sent successfully!" ;

}else{

echo "Email could not be sent." ;

}

?>

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Simple Send Mail

Mail Form

To
Subject
Message
Backend php code, save to mail.php ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <🎜>if (empty ($_POST['mailto']) ) {<🎜> <🎜>die ( "Recipient is blank! ") ;<🎜> <🎜>}<🎜> <🎜>if (empty ($_POST['$mailsubject']) ){<🎜> <🎜>$mailsubject=" " ;<🎜> <🎜>}<🎜> <🎜>if (empty ($_POST['$mailbody']) ) {<🎜> <🎜>$mailbody=" " ;<🎜> <🎜>}<🎜> <🎜>$result = mail ($mailto, $mailsubject, $mailbody) ;<🎜> <🎜>//send the email<🎜> <🎜>if ($result) {<🎜> <🎜>echo "Email sent successfully!" ;<🎜> <🎜>}else{<🎜> <🎜>echo "Email could not be sent." ;<🎜> <🎜>}<🎜> <🎜>?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/971947.htmlTechArticleHow to send emails by submitting forms in php. This article mainly introduces the method of sending emails by submitting forms in php, with an example analysis. The skills of sending emails using PHP forms are very practical and require...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template