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
WBOYOriginal
2016-07-13 10:01:24839browse

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...
Statement๏ผš
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